Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python get the key with the max or min value in a dictionary

# Basic syntax:
key_with_max_value = max(dictionary, key=dictionary.get)

# Note, to get the max value itself, you can do either of the following:
max_value = dictionary[max(dictionary, key=dictionary.get)]
max_value = max(dictionary.values())

# Example usage:
dictionary = {"a": 1, "b": 2, "c": 3}
max(dictionary, key=dictionary.get)
--> 'c'
Source by www.kite.com #
 
PREVIOUS NEXT
Tagged: #python #key #max #min #dictionary
ADD COMMENT
Topic
Name
5+4 =