Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9554

Re: Intersection problem

From Yi Wang <tririverwangyi@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Intersection problem
Date 2012-04-11 22:21 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jm504m$2n3$1@smc.vnet.net> (permalink)
References <jm0ju7$adk$1@smc.vnet.net>

Show all headers | View raw


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?

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


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