MathGroup Archive 2010

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

Search the Archive

Re; newbie list question

  • To: mathgroup at
  • Subject: [mg115026] Re; newbie list question
  • From: Richard Hofler <rhofler at>
  • Date: Tue, 28 Dec 2010 06:53:21 -0500 (EST)


I'm certain you'll get simpler solutions. However, here's one. . .

In[27]:== listA=={4,5,8,2,6,4};

In[29]:== Flatten[Table[First[Position[{listA},_?(#====listB[[a]]&)]],{a,3}]/.{1,x_}->{x}]
Out[29]== {3,1,4}

This shows how most parts of the final function work.

Position[{listA},_?(#====listB[[2]]&)]   (* example for only the 2nd element in ListB *)

First[Position[{listA},_?(#====listB[[2]]&)]]  (* example for the first location of only the 2nd element in ListB *)

Table[First[Position[{listA},_?(#====listB[[a]]&)]],{a,3}]  (* all of the elements in ListB *)



Out[37]== {{1,1},{1,6}}
Out[38]== {1,1}
Out[39]== {{1,3},{1,1},{1,4}}
Out[40]== {{3},{1},{4}}
Out[41]== {3,1,4}


Richard Hofler
From: Gareth Edwards [gareth.edwards at]
Sent: Sunday, December 26, 2010 4:02 AM
To: mathgroup at
Subject: [mg115026] [mg114986] newbie list question


Liking Mathematica a lot, but struggling with the early part of the learnin=
g 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!

  • Prev by Date: DSolve second order ODE wrong solution
  • Next by Date: Re: Mathematica daily WTF
  • Previous by thread: DSolve second order ODE wrong solution
  • Next by thread: Circular neighborhood for ImageApply