Skip to content
Related Articles

Related Articles

Second largest value in a Python Dictionary

Improve Article
Save Article
  • Last Updated : 07 Dec, 2022
Improve Article
Save Article

In this problem, we will find the second-largest value in the given dictionary.

Examples:

Input :  {'one':5, 'two':1, 'three':6, 'four':10}
Output :  Second largest value of the dictionary is 6

Input :   {1: 'Geeks', 'name': 'For', 3: 'Geeks'}
Output :  Second largest value of the dictionary is Geeks

Python3




dictionary = {1: 'Geeks', 'name': 'For', 3: 'Geeks'}
val = list(dictionary.values())
val.sort()
res = val[-2]
print(res)


Output:

Geeks

Time Complexity : O(n Log n) 
Auxiliary Space: O(n)

Please refer below post for more methods : Python program to find second maximum value in Dictionary

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!