Riffle
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 all close allBasic Examples (3)
Scope (7)
Riffle in x at every other position:
Riffle[{1, 2, 3, 4, 5, 6, 7, 8, 9}, x]Riffle[{1, 2, 3, 4, 5, 6, 7, 8, 9}, x, {2, -2, 2}]Include x at the beginning and end:
Riffle[{1, 2, 3, 4, 5, 6, 7, 8, 9}, x, {1, -1, 2}]Riffle[{1, 2, 3, 4, 5, 6, 7, 8, 9}, x, {1, -1, 3}]Start riffling in x only at position 5:
Riffle[{1, 2, 3, 4, 5, 6, 7, 8, 9}, x, {5, -1, 2}]Riffle[{1, 2, 3, 4, 5, 6, 7, 8, 9}, {x, y}, {5, -1, 2}]Riffle[{a, b, c, d}, {x, y, z, w}]Riffle works on SparseArray objects:
Riffle[SparseArray[5 -> 1, 10], x]Applications (5)
StringJoin[Riffle[{"this", "is", "an", "example"}, " "]]Create a directory name from a path list:
StringJoin[Riffle[{"usr", "local", "bin"}, "/"]]Insert 0s between successive integers:
Riffle[Range[10], 0]Alternate positive and negative integers:
Riffle[Range[10], -Range[10]]Insert commas at every 4
character:
StringJoin[Riffle[Characters["4345252523535"], ",", {-4, 1, -4}]]See Also
StringRiffle Insert Take PadLeft DelimitedSequence
Function Repository: Shuffle InShuffle OutShuffle BisectList EveryOther
Related Guides
History
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
BibTeX
@misc{reference.wolfram_2026_riffle, author="Wolfram Research", title="{Riffle}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Riffle.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_riffle, organization={Wolfram Research}, title={Riffle}, year={2007}, url={https://reference.wolfram.com/language/ref/Riffle.html}, note=[Accessed: 13-June-2026]}