Instagram
youtube
Facebook
Twitter

Python Program to Get the Key with Minimum Value from a Dictionary

A Python Program to Get the Key with Minimum Value from a Dictionary?

Code Explanation:

Dictionary Initialization:
A dictionary my_dict is created with subjects as keys and marks as values.

Finding Minimum Value Key:
min(my_dict, key=my_dict.get) is used to get the key that has the smallest value.

Use of key=my_dict.get:
This tells min() to compare values instead of keys when searching for the minimum.

Store the Result:
The key with the lowest value (minimum marks) is stored in the variable min_key.

Output Display:
The key having the minimum value is printed, showing which subject has the lowest score.

 

Program:

my_dict = {

    'Math': 88,

    'English': 75,

    'Science': 92,

    'History': 70

}

min_key = min(my_dict, key=my_dict.get)

print("Key with minimum value:", min_key)