-1

I need to get the highest key with the lowest value, since key 3 and key 6 have the same value, I can only get key 3 back but I need key 6 since it is the highest key.

dic = {1: 35, 2: 34, 3: 24, 4: 32, 5: 31, 6: 24}
  • Does this answer your question? [Get the key corresponding to the minimum value within a dictionary](https://stackoverflow.com/questions/3282823/get-the-key-corresponding-to-the-minimum-value-within-a-dictionary) - See [this answer](https://stackoverflow.com/a/50053777/) which gets all keys with lowest value, then just get the max – Nick is tired Aug 29 '21 at 05:14
  • @Nick That doesn't answer the whole question... – U13-Forward Aug 29 '21 at 05:15
  • @U12-Forward Then combine it with a duplicate for getting the max value in a list – Nick is tired Aug 29 '21 at 05:15
  • @Nick Yeah in one expression like in a tuple... like in my answer... it would work – U13-Forward Aug 29 '21 at 05:15
  • @U12-Forward In that case, it could easily be closed as a duplicate of: https://stackoverflow.com/questions/68405306/finding-the-dictionary-key-with-max-value It's identical except the obvious change of being min vs max... funny, you've already answered that one /shrug – Nick is tired Aug 29 '21 at 05:24
  • @Nick haha didn't notice that.... – U13-Forward Aug 29 '21 at 05:25
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 31 '21 at 03:08

1 Answers1

0

Try with max and set the key argument.

>>> max(dic, key=lambda x: (-dic[x], x))
6
>>> 

Set it to the lowest value and if they're the same set it to the highest key.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114