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}
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}
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.