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: [mg114966] Re: Building clusters out of a nested list
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 24 Dec 2010 04:13:24 -0500 (EST)

On 12/23/10 at 3:55 AM, dpesin at gmail.com (Dmitry) wrote:

>please, help me find a solution to the following problem:

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

Here is one way:

In[6]:= Union[
  Union /@ (Join @@@
     DeleteCases[
      Tuples[{{a, b, c}, {c, d}, {e, f}, {f, h}},
       2], _?(Intersection @@ # == {} || SameQ @@ # &)])]

Out[6]= {{e,f,h},{a,b,c,d}}

Note, this is a brute force method in that it makes a list of
all possible pairings. There may be a more elegant way to do
this. Also, notice I changed your variables to lower case. It is
unwise to use single uppercase characters as variables as many
of these already have built in meaning.



  • Prev by Date: Re: bibtex support in Mathematica 8
  • Next by Date: Re: Compare matrices using Chi square for Exploratory
  • Previous by thread: Re: Building clusters out of a nested list
  • Next by thread: Re: Building clusters out of a nested list