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"
Here is what the above code is Doing:
1. min() is a built-in function that returns the smallest item in an iterable.
2. a_dictionary.get is a method that returns the value of a key in a dictionary.
3. min(a_dictionary, key=a_dictionary.get) returns the key with the smallest value.