Riffle

Riffle[{e1, e2, ...}, x]
gives .

Riffle[{e1, e2, ...}, {x1, x2, ...}]
gives .

Riffle[list, x, n]
yields a list in which every n^(th) element is x.

Riffle[list, x, {imin, imax, n}]
yields a list in which x appears if possible at positions , , , ... , .

DetailsDetails

  • If there are fewer than gaps between in Riffle[{e1, e2, ...}, {x1, x2, ...}], the are used cyclically.
  • Riffle[{e}, x] gives {e}.
  • The specification 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.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Riffle between successive elements in a list:

In[1]:=
Click for copyable input
Out[1]=

Riffle in and cyclically:

In[1]:=
Click for copyable input
Out[1]=

Riffle in at every 3^(rd) position:

In[1]:=
Click for copyable input
Out[1]=
New in 6
New to Mathematica? Find your learning path »
Have a question? Ask support »