Consider the following example set
set = { {a,{1,2,3}} , {b,{1}} , {c,{2,3}} , {d,{4,5}} , {e,{5}} };
I would like to have a function (lets call it magic[x_]
) that looks at the lists set[[i,2]]
and groups the elements i
of set
into new sets such as to separate disjoint lists. For example:
magic[set]
{ { {a,{1,2,3}} , {b,{1}} , {c,{2,3}} } , { {d,{4,5}} , {e,{5}} } }
which grouped elemets containing lists with overlapping entries {1,2,3}
and {4,5}
but each disjoint from one another. Is there a function in Mathematica which can be used to achieve that? Or maybe this can be implemented conveniently? Thanks for any suggestion!
Gather[set, IntersectingQ[#1[[2]], #2[[2]]] &]
. It works for your example, but does it work for more generalset
s? $\endgroup$