SHARE
TWEET

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!
  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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top