MathGroup Archive 2012

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

Search the Archive

Re: Intersection problem


On Apr 10, 3:28 am, Cisco Lane <travl... at 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



  • Prev by Date: Re: Intersection problem
  • Next by Date: Re: Intersection problem
  • Previous by thread: Re: Intersection problem
  • Next by thread: Re: Intersection problem