Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Split a list into two sublists, gathering every other element of the list
| ResourceFunction["EveryOther"][{e1,e2,e3,e4,…}] returns {{e1,e3,…},{e2,e4,…}}. | |
| ResourceFunction["EveryOther"][{e1,e2,…},n] returns n sublists {{e1,e1+n,…},…{en,e2n,…}}. | 
Split the List, combining elements in odd and even positions:
| In[1]:= | ![ResourceFunction["EveryOther"][{1, 2, 3, 4, 5}]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/7ec201978528c462.png) | 
| Out[1]= |  | 
Group elements separated by gaps of length n:
| In[2]:= | ![ResourceFunction["EveryOther"][Range[10], 3]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/1d69503af2e4f596.png) | 
| Out[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]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/30cf83a5c1cdc641.png) | 
| Out[3]= |  | 
| In[4]:= | ![Transpose[Partition[list, 2]]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/0007be4fe00236c3.png) | 
| Out[4]= |  | 
| In[5]:= | ![ResourceFunction["EveryOther"][list]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/36b2b4016b14fe63.png) | 
| 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]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/2a30551c1f4f65c6.png) | 
| Out[6]= |  | 
| In[7]:= | ![Transpose[Partition[list, 3]]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/1bf4779ea719aed2.png) | 
| Out[7]= |  | 
| In[8]:= | ![ResourceFunction["EveryOther"][list, 3]](https://www.wolframcloud.com/obj/resourcesystem/images/8b4/8b4c8063-2163-498c-a742-1ad8b45c78c1/01961374d5bd8064.png) | 
| Out[8]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License