Answers for "max function python key"

20

python find the key with max value

a_dictionary = {"a": 1, "b": 2, "c": 3}

# get key with max value
max_key = max(a_dictionary, key=a_dictionary.get)

print(max_key)
Posted by: Guest on April-27-2020
0

python max with custom function

nums = [1,2,3,1,1,3,3,4,4,3,5] #list
counts = collections.Counter(nums) # create a dict of counts
#using counts.get() fun as custom function 
return max(counts.keys(), key=counts.get)
Posted by: Guest on May-06-2020

Python Answers by Framework

Browse Popular Code Answers by Language