Advertisement
muntoo

how to find maximum valued key in dictionary in python

Apr 17th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. Let's give that lambda function a name:
  2.  
  3.    def lookup(k):
  4.        return my_dict[k]
  5.  
  6. All it does is lookup the key `k` in your dictionary.
  7.  
  8. Then,
  9.  
  10.    key_max = max(my_dict.keys(), key=lookup)
  11.  
  12. simply finds the key with the largest lookup value.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement