Re: Intersection problem
- To: mathgroup at smc.vnet.net
- Subject: [mg126046] Re: Intersection problem
- From: Barrie Stokes <Barrie.Stokes at newcastle.edu.au>
- Date: Fri, 13 Apr 2012 04:56:50 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201204100627.CAA10654@smc.vnet.net>
Hi Fred Of the many offerings to this question, I like yours as much as any of them, as Pick [list1, list1[[All, 1]], Alternatives @@ list2 ] is quite transparent. Pick [list1, First /@ list1, Alternatives @@ list2 ] avoids the need to use "[[" and "]]", and needs even fewer characters. Looking through the recent postings in reply to Cisco's query, I think this question might be a contender for the title of "Question with the Most Syntactically Different Valid Answers"? (Steven M. Christensen?) Sort of companion to the well-known "One-Liner" competition ... Cheers Barrie >>> On 12/04/2012 at 8:16 am, in message <201204112216.SAA02663 at smc.vnet.net>, Fred Simons <f.h.simons at tue.nl> wrote: > Op 10-4-2012 8:27, Cisco Lane schreef: >> 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? >> >> > I am not sure if this is quick, but it is short: > > Pick[list1, list1[[All, 1]], Alternatives @@ list2] > > > Regards, > > Fred Simons > Eindhoven University of Technology
- References:
- Intersection problem
- From: Cisco Lane <travlorf@yahoo.com>
- Intersection problem