Function Repository Resource:

# GroupByList

Group elements according to a list of equivalence classes

Contributed by: Carl Woll
 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.

## Details and Options

ResourceFunction["GroupByList"][list,equiv] gives an Association whose keys are the distinct equivi and whose values are sublists of the list list.
ResourceFunction["GroupByList"][f/@data,g/@data] is equivalent to GroupBy[data,fg].
The association keys equivi are ordered according to their first appearance in the list of equivalence classes.

## Examples

### Basic Examples (1)

Group elements based on their equivalence classes:

 In:= Out= ### Scope (2)

Consider two datasets:

 In:= Out= In:= Out= Group the positions by the relative order of left and right:

 In:= Out= ### Applications (2)

Find all partitions of the list {a,b,c,d,e} with sublists of length 2, 2 and 1. The possible permutations are:

 In:= Out= Each permutation gives an equivalence class of the list:

 In:= Out= ### Properties and Relations (2)

GroupByList uses a list of equivalence classes:

 In:= Out= GroupBy uses a equivalence function:

 In:= Out= GroupByList[f/@data,g/@data] is equivalent to GroupBy[data,fg]. Using GroupByList:

 In:= Out= Using GroupBy:

 In:= Out= Carl Woll

## Version History

• 1.0.0 – 13 November 2019