Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Intersection problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125980] Re: Intersection problem
  • From: Murta <rodrigomurtax at gmail.com>
  • Date: Wed, 11 Apr 2012 18:17:22 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jm0ju7$adk$1@smc.vnet.net>

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