Finding The Biggest Key In A Python Dictionary?

PythonProgramming

If you have a dict with string-integer mappings, you can use the max method on the dictionary's item pairs to get the largest value. 

example

d = {
   'foo': 100,
   'bar': 25,
   'baz': 360
}
print(max(k for k, v in d.items()))

Output

This will give the output −

foo

foo is largest in alphabetical order.

raja
Published on 19-Apr-2018 07:28:34
Advertisements