# How to get back name of the number from Max function? [duplicate]

So I have this question, using a toy example:

a={1,"this"};
b={2,"that"};

result=Max[0,a[[1]],b[[1]]]


the result will be 2. However what I want to obtain is "that" (or at least "b"). How do I do this without making dozens of "If"s and conditionals??

-

## marked as duplicate by Mr.Wizard♦Dec 6 '13 at 21:25

a = {1, "this"}; b = {2, "that"}; #[[Ordering[#, -1, #[[1]] &]]] &@{a, b}? –  belisarius Dec 6 '13 at 20:43
thank you so much, pretty nice one! –  Strumillo Dec 6 '13 at 21:19
Shorter a = {1, "this"}; b = {2, "that"}; #[[Ordering[#, -1]]] &@{a, b} –  belisarius Dec 6 '13 at 21:25
I have marked this as a duplicate. I feel that the subject is already well covered there. (And several other places.) Please review the answers there; if afterward you disagree vote or flag to reopen. –  Mr.Wizard Dec 6 '13 at 21:27
Mods should have a way to vote normally –  belisarius Dec 6 '13 at 21:34

If you have Mathematica on the Raspberry Pi (or Mathematica 10), you could use Association to store your data, which allows you to do these operations easily:

With[{a = <|1 -> "this", 2 -> "that"|>},
a@Max@Keys@a
]
(* that *)


You can convert your list to an association as: Association @@ Rule @@@ {a, b}

-
Show a screen capture, or it didn't happen –  belisarius Dec 6 '13 at 21:15
@belisarius Now vote! :D –  rm -rf Dec 6 '13 at 21:16
Ok, Ok, you have it :) –  belisarius Dec 6 '13 at 21:19
a={1,"this"};
b={2,"that"};

Max[0, a[[1]], b[[1]]] /. Rule @@@ {a, b}


This gives :

that

-
wooooooow, thank you! –  Strumillo Dec 6 '13 at 20:57
can I ask one more thing? how do I get whole b back? I'm just mesmerized by 3 @@@ and how it works:) –  Strumillo Dec 6 '13 at 20:59
To obtain {2,"that"} instead of "that", you can do Max[0, a[[1]], b[[1]]] /. ((#[[1]] -> #) & /@ {a, b}) –  andre Dec 6 '13 at 21:04
a={1,"this"};
b={2,"that"};

Cases[{a, b}, {key_, value_} /; (key == Max[{a, b}[[All, 1]]])]


or

Select[{a, b}, (#[[1]] == Max[{a, b}[[All, 1]]] &)]


For variety's sake. Likely not the way to go for long lists though.

-