muntoo

how to find maximum valued key in dictionary in python

Apr 17th, 2018
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.
RAW Paste Data