With a nested list such as
listA = {{{a,b,c},{1,0,0}}, {{a,b,c},{0,1,0}}, {{d,e,f},{1,1,0}}};
How can I create
listB = {{{a,b,c},{{1,0,0},{0,1,0}}}, {{d,e,f},{1,1,0}}};
and so-forth for any length of listA
?
With a nested list such as
listA = {{{a,b,c},{1,0,0}}, {{a,b,c},{0,1,0}}, {{d,e,f},{1,1,0}}};
How can I create
listB = {{{a,b,c},{{1,0,0},{0,1,0}}}, {{d,e,f},{1,1,0}}};
and so-forth for any length of listA
?
KeyValueMap[List] @ GroupBy[listA, First -> Last]
Values @ GroupBy[listA, First, {#[[1, 1]], #[[All, 2]]}&]
KeyValueMap[List] @ Merge[Association /@ Rule @@@ listA, Identity]
{#[[1, 1]], #[[All, 2]]} & /@ GatherBy[listA, First]
all give
{{{a, b, c}, {{1, 0, 0}, {0, 1, 0}}}, {{d, e, f}, {{1, 1, 0}}}}