Function Repository Resource:

EveryOther

Source Notebook

Split a list into two sublists, gathering every other element of the list

Contributed by: Wolfram Staff

ResourceFunction["EveryOther"][{e1,e2,e3,e4,}]

returns {{e1,e3,},{e2,e4,}}.

ResourceFunction["EveryOther"][{e1,e2,},n]

returns n sublists {{e1,e1+n,},{en,e2n,}}.

Details and Options

For a list of even length, ResourceFunction["EveryOther"][list] is equivalent to Transpose[Partition[list,2]].
If n evenly divides the list length, ResourceFunction["EveryOther"][list,n] is equivalent to Transpose[Partition[list,n]].

Examples

Basic Examples (2) 

Split the List, combining elements in odd and even positions:

In[1]:=
ResourceFunction["EveryOther"][{1, 2, 3, 4, 5}]
Out[1]=

Group elements separated by gaps of length n:

In[2]:=
ResourceFunction["EveryOther"][Range[10], 3]
Out[2]=

Properties and Relations (2) 

Transpose[Partition[list,2]] gives the same result as EveryOther[list], as long as list has an even number of elements:

In[3]:=
list = Range[10]
Out[3]=
In[4]:=
Transpose[Partition[list, 2]]
Out[4]=
In[5]:=
ResourceFunction["EveryOther"][list]
Out[5]=

Transpose[Partition[list,n]] gives the same result as EveryOther[list,n], as long n evenly divides Length[list]:

In[6]:=
list = Range[12]
Out[6]=
In[7]:=
Transpose[Partition[list, 3]]
Out[7]=
In[8]:=
ResourceFunction["EveryOther"][list, 3]
Out[8]=

Version History

  • 1.0.0 – 31 August 2020

Related Resources

License Information