Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9371 > unrolled thread
| Started by | Cisco Lane <travlorf@yahoo.com> |
|---|---|
| First post | 2012-04-03 08:44 +0000 |
| Last post | 2012-04-04 08:35 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
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
| From | Cisco Lane <travlorf@yahoo.com> |
|---|---|
| Date | 2012-04-03 08:44 +0000 |
| Subject | Find 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]
| From | Helen Read <readhpr@gmail.com> |
|---|---|
| Date | 2012-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]
| From | Murta <rodrigomurtax@gmail.com> |
|---|---|
| Date | 2012-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