Max and Min Dictionary Values

Write a Python program to get the maximum and minimum value in a dictionary.

Example 1:

Input: {"a": 5, "b": 3, "c": 8} 
Output: (8, 3)

Example 2:

Input: {"x": 7, "y": 6, "z": 9} 
Output: (9, 6)

You can use Python’s built-in max() and min() functions and dict.values() method.

def max_min_dict(d):
    return (max(d.values()), min(d.values()))

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!