5

Is there a function in Mathematica that compares two lists and take from first the element with the position of largest value at second:

  list1= {a,b}; list2={1,2}; out = b
Ask8
  • 637
  • 3
  • 6

3 Answers3

8

If you are looking for one built-in function does this job, I think there's no such function at the moment, but your goal can be easily achieved by

list1[[Ordering[list2, -1]]]
xzczd
  • 65,995
  • 9
  • 163
  • 468
1
MaximalBy[Transpose[{{a, b, c}, {1, 2, 3}}], Last]
matrix42
  • 6,996
  • 2
  • 26
  • 62
0

Just realised @Corey979 mentioned the same in comments but my method would use Pick

list1={a,b,c,d,e}
list2=RandomInteger[10,5] = {0,7,7,9,1}

Pick[list1,list2,Max[list2]]
Out[54]= {d}
Teabelly
  • 1,004
  • 5
  • 14