CBSE Class 11 Informatics Practices Question 43 of 66

Dictionary — Question 15

Back to all questions
15
Question

Question 5

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

Solution
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
Answer