Riffle
Riffle[{e1,e2,…},x]
gives {e1,x,e2,x,…}.
Riffle[{e1,e2,…},{x1,x2,…}]
gives {e1,x1,e2,x2,…}.
Riffle[list,x,n]
yields a list in which every n element is x.
Riffle[list,x,{imin,imax,n}]
yields a list in which x appears if possible at positions imin, imin+n, imin+2n, … , imax.
Details
- If there are fewer xi than gaps between ei in Riffle[{e1,e2,…},{x1,x2,…}], the xi are used cyclically.
- Riffle[{e},x] gives {e}.
- The specification {imin,imax,n} is of the type used in Take. Negative indices count from the end of the list.
- Riffle[list,x] is equivalent to Riffle[list,x,{2,-2,2}].
- Riffle[list,x,n] is equivalent to Riffle[list,x,{n,-2,n}].
- In Riffle[list,xlist], if list and xlist are of the same length, then their elements are directly interleaved, so that the last element of the result is the last element of xlist.
- Riffle works with SparseArray objects.
Examples
open allclose allBasic Examples (3)
Scope (7)
Riffle in x at every other position:
Include x at the beginning and end:
Start riffling in x only at position 5:
Riffle works on SparseArray objects:
Applications (5)
Text
Wolfram Research (2007), Riffle, Wolfram Language function, https://reference.wolfram.com/language/ref/Riffle.html.
CMS
Wolfram Language. 2007. "Riffle." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Riffle.html.
APA
Wolfram Language. (2007). Riffle. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Riffle.html