5
$\begingroup$

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
$\endgroup$
8
$\begingroup$

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]]]
$\endgroup$
1
$\begingroup$
MaximalBy[Transpose[{{a, b, c}, {1, 2, 3}}], Last]
$\endgroup$
0
$\begingroup$

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}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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