Informatics Practices

Write a Python program to find the highest 2 values in a dictionary.

Python Dictionaries

7 Likes

Answer

d = {'a': 10, 'b': 30, 'c': 20, 'd': 50, 'e': 40}
s = sorted(d.values())
print("Dictionary:", d)
print("Highest 2 values are:", s[-1], s[-2])

Output

Dictionary: {'a': 10, 'b': 30, 'c': 20, 'd': 50, 'e': 40}
Highest 2 values are: 50 40

Answered By

5 Likes


Related Questions