python dictionary get min value code example

Example 1: python min in dictionary

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

# get key with min value
min_key = min(a_dictionary, key=a_dictionary.get)

print(min_key)
# print output => "a"

Example 2: 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)

Example 3: python get min max value from a dictionary

d = {'A': 4,'B':10}
min_v = min(zip(d.values(), d.keys()))
# min_v is (4,'A')

max_v = max(zip(d.values(), d.keys()))
# max_v is (10,'B')