Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Partition an association into a list of associations
ResourceFunction["AssociationPartition"][assoc,n] partitions the association assoc into a list of nonoverlapping associations of length n. | |
ResourceFunction["AssociationPartition"][assoc,n,d] generates associations with offset d. |
Partition into associations of length 2:
In[1]:= | ![]() |
Out[1]= | ![]() |
Partition into associations of length 3 with offset 1:
In[2]:= | ![]() |
Out[2]= | ![]() |
Incomplete sublists at the end are by default dropped:
In[3]:= | ![]() |
Out[3]= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
Allow for a "ragged" partition, wherein last elements can be shorter:
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
AssociationPartition extends Partition to work on associations:
In[7]:= | ![]() |
Out[7]= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
A partitioned List of associations can be re-combined using Association:
In[9]:= | ![]() |
Out[9]= | ![]() |
In[10]:= | ![]() |
Out[10]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License