how to find maximum valued key in dictionary in python
muntoo Apr 17th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- Let's give that lambda function a name:
- def lookup(k):
- return my_dict[k]
- All it does is lookup the key `k` in your dictionary.
- key_max = max(my_dict.keys(), key=lookup)
- simply finds the key with the largest lookup value.
RAW Paste Data