4
$\begingroup$

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!

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

1 Answer 1

10
$\begingroup$

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]
Extract[list,p]

where list is the list you want to extract from.

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

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