Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Group elements according to a list of equivalence classes
ResourceFunction["GroupByList"][{elem1,elem2,…},{equiv1,equiv2,…}] gives an association that groups the elemi into lists associated with distinct keys equivi. | |
ResourceFunction["GroupByList"][{elem1,elem2,…}, {equiv1, equiv2,…} ,red] applies the function red to reduce lists of values that are generated. |
Group elements based on their equivalence classes:
In[1]:= |
Out[1]= |
Consider two datasets:
In[2]:= |
Out[3]= |
In[4]:= |
Out[4]= |
Group the positions by the relative order of left and right:
In[5]:= |
Out[5]= |
Find all partitions of the list {a,b,c,d,e} with sublists of length 2, 2 and 1. The possible permutations are:
In[6]:= |
Out[6]= |
Each permutation gives an equivalence class of the list:
In[7]:= |
Out[7]= |
This work is licensed under a Creative Commons Attribution 4.0 International License