Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9371 > unrolled thread

Find common elements in a list of sublists

Started byCisco Lane <travlorf@yahoo.com>
First post2012-04-03 08:44 +0000
Last post2012-04-04 08:35 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Find common elements in a list of sublists Cisco Lane <travlorf@yahoo.com> - 2012-04-03 08:44 +0000
    Re: Find common elements in a list of sublists Helen Read <readhpr@gmail.com> - 2012-04-04 08:30 +0000
    Re: Find common elements in a list of sublists Murta <rodrigomurtax@gmail.com> - 2012-04-04 08:35 +0000

#9371 — Find common elements in a list of sublists

FromCisco Lane <travlorf@yahoo.com>
Date2012-04-03 08:44 +0000
SubjectFind common elements in a list of sublists
Message-ID<jleda1$gjk$1@smc.vnet.net>
Suppose I have a list of sublists:

d={{1, 19}, {1, 23}, {1, 5, 25}, {1, 17}, {1, 11}, {1, 5}}

How do I find the elements common to all the sublists?

I can do it using intersection:

Intersection[dx[[1]], dx[[2]], dx[[3]], dx[[4]], dx[[5]], dx[[6]]]

which yields, correctly, {1}, but what if the number of sublists in d is variable?

[toc] | [next] | [standalone]


#9392

FromHelen Read <readhpr@gmail.com>
Date2012-04-04 08:30 +0000
Message-ID<jlh0r4$t8h$1@smc.vnet.net>
In reply to#9371
On 4/3/2012 4:44 AM, Cisco Lane wrote:
> Suppose I have a list of sublists:
>
> d={{1, 19}, {1, 23}, {1, 5, 25}, {1, 17}, {1, 11}, {1, 5}}
>
> How do I find the elements common to all the sublists?
>
> I can do it using intersection:
>
> Intersection[dx[[1]], dx[[2]], dx[[3]], dx[[4]], dx[[5]], dx[[6]]]
>
> which yields, correctly, {1}, but what if the number of sublists in d is variable?
>

MapThread[Intersection, d, 0]

-- 
Helen Read
University of Vermont

[toc] | [prev] | [next] | [standalone]


#9401

FromMurta <rodrigomurtax@gmail.com>
Date2012-04-04 08:35 +0000
Message-ID<jlh13v$36$1@smc.vnet.net>
In reply to#9371
On Apr 3, 5:44 am, Cisco Lane <travl...@yahoo.com> wrote:
> Suppose I have a list of sublists:
>
> d={{1, 19}, {1, 23}, {1, 5, 25}, {1, 17}, {1, 11}, {1, 5}}
>
> How do I find the elements common to all the sublists?
>
> I can do it using intersection:
>
> Intersection[dx[[1]], dx[[2]], dx[[3]], dx[[4]], dx[[5]], dx[[6]]]
>
> which yields, correctly, {1}, but what if the number of sublists in d is variable?

Hi Lane
You can use this:

d = {{1, 19}, {1, 23}, {1, 5, 25}, {1, 17}, {1, 11}, {1, 5}};
Intersection @@ d

best regards
Murta

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web