Group: Difference between revisions
Content added Content deleted
("Remove lowercase again - it is in the template now") Tag: Manual revert |
("Paragraph cleanup") |
||
(3 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
`a`b`c`d`k!(0 1 7 8;,2;3 4 6;,5;,9) |
`a`b`c`d`k!(0 1 7 8;,2;3 4 6;,5;,9) |
||
</pre> |
</pre> |
||
The [[keys]] from the '''group''' dictionary represent the [[distinct]] elements of the array. |
The [[keys]] from the '''group''' dictionary represent the [[distinct]] elements of the array. |
||
Line 21: | Line 19: | ||
"abrcd" |
"abrcd" |
||
</pre>{{Works in|ngn/k}} |
</pre>{{Works in|ngn/k}} |
||
In K2 and K3, the group primitive returns a nested array:<pre> |
In K2 and K3, the group primitive returns a nested array:<pre> |
||
Line 46: | Line 43: | ||
)) |
)) |
||
</pre>{{Works in|Kona}} |
</pre>{{Works in|Kona}} |
||
[[Category:Verbs]] |
|||
[[Category:Operator verbs]] |
|||
[[Category:Primitives]] |
Latest revision as of 07:59, 9 July 2022
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
In K2 and K3, the group primitive returns a nested array:
="abracadabra" (0 3 5 7 10 1 8 2 9 ,4 ,6)
Works in: Kona
In order to mimic the K6 behaviour, you can use distinct: {(?x)!=x}
to get a dict.
{(?:x)!=x}`a`a`b`c .((`a 0 1 ) (`b ,2 ) (`c ,3 ))
Works in: Kona