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
KeyTake[asso, {{"a", "h"}}]
... $\endgroup$Key
to work. I think you should report it to WRI. $\endgroup${x,y,...}
is an argument with multiple keys,{{x,y,...}}
is an argument with a single, compound key. $\endgroup$