Tally[list,test]
can use a custom function test
to judge if elements are equal. But the output will only give the first element in a group. Is there an option to give all the elements? Or how do I write a custom function to do this?
E.g. Given {{1,1},{1,2},{1,2,3},{2,3}}
, a tally with test set to head equality would give {{{1,1},3},{{2,3},1}}
, but I want something like {{3,{1,1},{1,2},{1,2,3}},{1,{2,3}}}
.
union
against aGather
is what you're after, but you need to give a more useful description. $\endgroup$Map[{#, Length@#} &, Union /@ Gather[#, <test>]] &@<object>
is what you're after, with <test> being the equality test and <object> the target... $\endgroup$Gather
rather thanGatherBy
? $\endgroup$GatherBy
is faster when applicable. $\endgroup$