Re: newbie list question
- To: mathgroup at smc.vnet.net
- Subject: [mg114995] Re: newbie list question
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Tue, 28 Dec 2010 06:47:37 -0500 (EST)
The following will do it:
Flatten[First@Position[listA, #] & /@ listB]
That's a "functional" method. Doubtless there's a (possibly simpler)
pattern-matching method as well.
On 12/26/2010 4:02 AM, Gareth Edwards wrote:
> Hi,
>
> Liking Mathematica a lot, but struggling with the early part of the learning curve, i.e. don't know what I don't know...
>
> What would be the neatest syntax for finding the first location of elements from one list in another? For example:
>
> listA = { 4,5,8,2,6,4 }
> listB = { 8,4,2 }
>
>
> I would like a function to return {3,1,4} in this case (the first location in A of each element in B)
>
> Many thanks!
>
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305