Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Combine multiple lists into a single list by interleaving their elements in sequence
ResourceFunction["Interleave"][list1,list2,…] interleaves elements from multiple lists, alternating between them in the order that the lists are provided. |
Interleave two lists:
In[1]:= | ![]() |
Out[1]= | ![]() |
Lists of varying length:
In[2]:= | ![]() |
Out[2]= | ![]() |
Interleave three lists:
In[3]:= | ![]() |
Out[3]= | ![]() |
Interleave with an empty list:
In[4]:= | ![]() |
Out[4]= | ![]() |
Interleaving a single list remains unchanged:
In[5]:= | ![]() |
Out[5]= | ![]() |
For two lists of the same length, Interleave is equivalent to Riffle:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
If the second list is shorter than the first, Riffle will repeat elements from the second list:
In[8]:= | ![]() |
Out[8]= | ![]() |
Interleave will concatenate the remaining elements of the longer list at the end:
In[9]:= | ![]() |
Out[9]= | ![]() |
If the first list is shorter than the second, Riffle will only use elements from the first list up to its length:
In[10]:= | ![]() |
Out[10]= | ![]() |
Interleave will concatenate the remaining elements of the longer list at the end:
In[11]:= | ![]() |
Out[11]= | ![]() |
Wolfram Language 14.0 (January 2024) or above
This work is licensed under a Creative Commons Attribution 4.0 International License