group

From The K Language Wiki
Revision as of 22:26, 9 July 2021 by Traws (talk | contribs)
Group
=x

The group primitive, denoted by =, is used to group the indices of an array by the values they represent in the array, returning a dictionary.

 =`a`a`b`c`c`d`c`a`a`k
`a`b`c`d`k!(0 1 7 8;,2;3 4 6;,5;,9)

The keys from the group dictionary represent the distinct elements of the array.

 ="abracadabra"
"abrcd"!(0 3 5 7 10;1 8;2 9;,4;,6)

 !="abracadabra"
"abrcd"
 ?"abracadabra"
"abrcd"
Works in: ngn/k