# From list shown below - highlight in BOLD the pair with the highest value

I have been trying for sometime to achieve the following:- Given the list - {{"E", 3}, {"D", 2}, {"S", 2}, {"M", 2}} a list of pairs which maybe 4 pairs - more or less... This list is an output of a previous calculation - so the result can be different every calculation. I need the output list shown above to highlight in BOLD the pair with the highest value. Thus the result would look like - {{"E", 3}, {"D", 2}, {"S", 2}, {"M", 2}} in this case. I am sure the answer is so simple, but I can't find it. Please could anyone advise how to do this with coding. Many thanks for your help & suggestions.

• highlightLargest[list_List,f_:Last]:=With[{max=First@TakeLargestBy[list,f,1]},Map[If[#===max,Style[#,Bold],#]&,list]] should do the trick but the output of this can not be used computationally anymore (unless one removes the Style wrapper from the largest element with e.g. a rule like Style[x_, ___] :> x.
– N0va
May 3, 2022 at 7:22
• I request you to take a look at the book written by the inventor; Chapter 7 specifically.
– Syed
May 3, 2022 at 7:41
• If you have your result in a variable called list, you can use MapAt[Style[#, Bold] &, list, OrderingBy[list, Last, -1]] May 3, 2022 at 8:21
• Many thanks for everyone's help - I think this answer works best for my situation - MapAt[Style[#, Bold] &, list, OrderingBy[list, Last, -1]] Many thanks Ben Izd May 3, 2022 at 9:45
• If @BenIzd doesn't post an answer, feel free to post your solution as an answer instead of a comment. May 3, 2022 at 16:43

You can highlight the largest case with MapAt:
MapAt[Style[#, Bold] &, list, OrderingBy[list, Last, -1]]

In the last argument, I used OrderingBy to find the index of the largest element.