In this example, you will learn how to get the maximum and minimum value in a dictionary.
Example 1: Get key with min value
1 2 3 4 5 6 7 8 9 10 11 12 | dictionary = {"a": 5, "b": 2, "c": 8} # get key with min value min_key = min(dictionary, key=dictionary.get) print(min_key) # print output => "b" print(dictionary.get(min_key)) # min value |
Example 2: Get key with max value
1 2 3 4 5 6 7 8 9 10 11 12 | dictionary = {"a": 5, "b": 2, "c": 8} # get key with min value max_key = max(dictionary, key=dictionary.get) print(max_key) # print output => "c" print(dictionary.get(max_key)) # max value |