Python Dictionary – Return key with the smallest value in a dictionary

In this post we will be retrieving the key with the smallest value in a dictionary, dictionaries in Python provide a means of storing multiple pieces of data in to a single variable. Data within a dictionary is stored in pairs, whereby there are keys and values.

See below our dictionary for this example.

Dict={1:3, 2:6, 3:1, 4:43, 5:24, 6:54, 7:32, 8:21, 9:41, 10:21}

See the snippet of code below where we find the key with the smallest value using Pythons inbuilt functions ‘min()’ function.

Key=min(Dict,key=Dict.get)
print(Key)

The above would return the following as output. Our key ‘3’ has the value of ‘1’ which is the smallest value within the dictionary.

3
>>> 

Leave a Reply