MathGroup Archive 2012

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

Search the Archive

Re: Intersection problem


There should be many ways to do it. The question is to find a good one. The simplest I can think of is:

first = {{a, x}, {b, y}, {c, z}};
second = {b, c, d};
Select[first, MemberQ[second, #[[1]]] &]

There are also some more complicated realisations, such as

first[[#]] & /@ 
 Flatten@Map[Position[Transpose[first][[1]], #] &, second]

Best,
Yi

On Tuesday, April 10, 2012 2:28:23 AM UTC-4, Cisco Lane 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?




  • Prev by Date: Re: Intersection problem
  • Next by Date: Re: Text["x=" x] reverses order of terms producing the string: 1.2 x=
  • Previous by thread: Re: Intersection problem
  • Next by thread: Integrate problem