# partition -- partition a set or list by values of a function

## Synopsis

• Usage:
partition(f,L)
• Inputs:
• f,
• L, , or
• Outputs:
• , whose keys are the possible values of the function f on the elements of the list, set or tally L, and the corresponding value of the hash table is the list, set or tally of elements of L which take that value under f

## Description

 ```i1 : L = {1,3,6,5,3,1,2,8,8,8} o1 = {1, 3, 6, 5, 3, 1, 2, 8, 8, 8} o1 : List``` ```i2 : partition(odd, L) o2 = HashTable{false => {6, 2, 8, 8, 8}} true => {1, 3, 5, 3, 1} o2 : HashTable``` ```i3 : partition(odd, set L) o3 = HashTable{false => set {2, 6, 8}} true => set {1, 3, 5} o3 : HashTable``` ```i4 : partition(odd, tally L) o4 = HashTable{false => Tally{2 => 1}} 6 => 1 8 => 3 true => Tally{1 => 2} 3 => 2 5 => 1 o4 : HashTable```
The following example parititions the generators of an ideal by degree.
 ```i5 : R = QQ[a..f] o5 = R o5 : PolynomialRing``` ```i6 : I = ideal"ab,ade,ac3,d4,b3,adf,f4,e10" 3 4 3 4 10 o6 = ideal (a*b, a*d*e, a*c , d , b , a*d*f, f , e ) o6 : Ideal of R``` ```i7 : partition(f -> first degree f, flatten entries gens I) o7 = HashTable{2 => {a*b} } 3 3 => {a*d*e, b , a*d*f} 3 4 4 4 => {a*c , d , f } 10 10 => {e } o7 : HashTable```