MathGroup Archive 2010

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

Search the Archive

Re: Building clusters out of a nested list

On Thursday, December 23, 2010 3:56:51 AM UTC-5, Dmitry wrote:


> 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}}.


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