MathGroup Archive 2012

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

Search the Archive

Re: Intersection problem


Three solutions


In[1]:= Select[{{a, x}, {b, y}, {c, z}}, MemberQ[{b, c, d}, #1[[1]]] & ]
Out[1]= {{b, y}, {c, z}}
In[2]:= Cases[{{a, x}, {b, y}, {c, z}}, {i_, _} /; MemberQ[{b, c, d}, i]]
Out[2]= {{b, y}, {c, z}}
In[3]:= Cases[{{a, x}, {b, y}, {c, z}}, {Alternatives @@ {b, c, d}, _}]
Out[3]= {{b, y}, {c, z}}


Adriano Pascoletti

2012/4/10 Cisco Lane <travlorf at yahoo.com>

> 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: HostMath - Generate and embed math equations or mathematical formulas in a blog or website
  • Next by Date: Re: Intersection problem
  • Previous by thread: Re: Intersection problem
  • Next by thread: Re: Intersection problem