say, I want to find an index of a specific element in a list using

Position[{a, b, c, d, e, f}, c]

and it returns {{3}}

How can I use this returned value as index to pick a certain element from another list? How can I convert {{3}} to an integer or is there any other way to achieve what I want to do?

Thanks in advance!

  • $\begingroup$ Related: (1508), (21966) $\endgroup$ – Mr.Wizard Sep 24 '17 at 19:39
  • $\begingroup$ Another possibility is PositionIndex with Part. For example: PositionIndex[list1][c] // list2[[#]] & $\endgroup$ – user1066 Sep 24 '17 at 22:01

If you put your cursor on the Position command and press F1 for help, you will see the following under Properties and Relations: "Use Extract to extract parts based on results from Position." There is also an example. For your case:

p = Position[{a, b, c, d, e, f}, c]

where list is the list you want to extract from.

  • $\begingroup$ Thanks, Bill. Should have looked the docs up more closely. $\endgroup$ – Peng Sep 24 '17 at 14:09
  • 2
    $\begingroup$ F1 is your friend. $\endgroup$ – bill s Sep 24 '17 at 14:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.