Max and min values

EasyDictionary Programs · 26 of 94

Write a Python program to find the maximum and minimum values of a dictionary, with their keys.

Advertisement
Input
{"a": 10, "b": 44, "c": 60, "d": 25}
Output
Maximum value: 60 at key c
Minimum value: 10 at key a

Approach

  1. max(d, key=d.get) returns the key with the largest value.

Solution

Python
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
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs