Re: Building clusters out of a nested list
- To: mathgroup at smc.vnet.net
- Subject: [mg114982] Re: Building clusters out of a nested list
- From: Vince Virgilio <blueschi at gmail.com>
- Date: Sun, 26 Dec 2010 04:01:38 -0500 (EST)
- Reply-to: comp.soft-sys.math.mathematica at googlegroups.com
On Thursday, December 23, 2010 3:56:51 AM UTC-5, Dmitry wrote:
SNIP
> suppose I have a list of the form { {A,B,C},{C,D},{E,F},{F,H}}. I need
> to build a list whose entries are unions of all entries of the
> original list with nonzero intersection. For the example above, the
> end result is {{A,B,C,D},{E,F,H}}.
SNIP
This works for your case and a few others. And it might scale better than other solutions, since I think it uses the pattern matcher less.
l = {{a, b, c}, {c, d}, {e, f}, {f, h}};
Outer[UnsameQ@## && Intersection@## =!= {} && Union@## &, l, l, 1] //
DeleteDuplicates@Level[#, {-2}] &
{{a, b, c, d}, {e, f, h}}
Vince Virgilio