Python Practice › Dictionary Programs › Program 26
Max and min values
Write a Python program to find the maximum and minimum values of a dictionary, with their keys.
Input
{"a": 10, "b": 44, "c": 60, "d": 25}Output
Maximum value: 60 at key c Minimum value: 10 at key a
Approach
max(d, key=d.get)returns the key with the largest value.
Solution
d = {"a": 10, "b": 44, "c": 60, "d": 25}print("Maximum value:", max(d.values()), "at key", max(d, key=d.get))print("Minimum value:", min(d.values()), "at key", min(d, key=d.get))Output
Maximum value: 60 at key c Minimum value: 10 at key a
Learn the concept
New to this topic? Read the lesson, then come back.