list = {{a, b, c, e}, {1, 2, b, h}, {"a", "h", 3, 5}};
asso = GroupBy[list, {#[[1]], #[[2]]} &]
<|{a, b} -> {{a, b, c, e}},
{1, 2} -> {{1, 2, b, h}},
{"a","h"} -> {{"a", "h", 3, 5}}|>
There is a problem in this code, since "a"
and "h"
might be two keys. However, KeyExistsQ
is not Listable
, but KeyTake
is.
KeyExistsQ[asso, {"a", "h"}]
True
KeyTake[asso, {"a", "h"}]
<||>
So I wrap Key
around {"a", "h"}
to eliminate ambiguity.
KeyTake[asso, Key[{"a", "h"}]]
<||>
Contrast the above with
KeyDrop[asso, Key[{"a", "h"}]]
<|{a, b} -> {{a, b, c, e}}, {1, 2} -> {{1, 2, b, h}}|>
Have I found a bug? Tested on V10.4
Comments
Post a Comment