Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

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


  • Prev by Date: newbie list question
  • Next by Date: Re: Mathematica 8 & reports / books
  • Previous by thread: Re: Building clusters out of a nested list
  • Next by thread: Glitch with having Graphics along with printouts dynamically