Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9551
| From | Murta <rodrigomurtax@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Intersection problem |
| Date | 2012-04-11 22:19 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jm500s$2lf$1@smc.vnet.net> (permalink) |
| References | <jm0ju7$adk$1@smc.vnet.net> |
On Apr 10, 3:28 am, Cisco Lane <travl...@yahoo.com> wrote:
> I need to select out the elements of the first list whose first elements
are contained in the second list. For example
>
> first list: {{a,x},{b,y},{c,z}}
>
> second list: {b,c,d}
>
> result: {{b,y},{c,z}}
>
> Is there a quick way to do this? Intersection, maybe somehow?
Hi Lane
There are 2 ways to do that:
l1 = {{a, x}, {b, y}, {c, z}}; l2 = {b, c, d};
number 1
Select[l1, MemberQ[l2, #[[1]]] &]
number 2
Cases[l1, {a_ /; MemberQ[l2, a], _}]
best regards
Murta
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Intersection problem Cisco Lane <travlorf@yahoo.com> - 2012-04-10 06:28 +0000 Re: Intersection problem Jason Ebaugh <ebaughjason@gmail.com> - 2012-04-11 22:18 +0000 Re: Intersection problem Murta <rodrigomurtax@gmail.com> - 2012-04-11 22:19 +0000 Re: Intersection problem Yi Wang <tririverwangyi@gmail.com> - 2012-04-11 22:21 +0000
csiph-web