Second largest value in a Python Dictionary
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
dictionary = {1: 'Geeks', 'name': 'For', 3: 'Geeks'} val = list(dictionary.values()) val.sort() res = val[-2] print(res) |
chevron_right
filter_none
Output:
Geeks
Time Complexity : O(n Log n)
Please refer below post for more methods :
Python program to find second maximum value in Dictionary
Recommended Posts:
- Python | Convert nested dictionary into flattened dictionary
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert string dictionary to dictionary
- Python | Get key from value in Dictionary
- Python | Get the first key in dictionary
- Python Dictionary
- Python | Check if key has Non-None value in dictionary
- Python Dictionary | pop() method
- Python | Get first N key:value pairs in given dictionary
- Python | Key index in Dictionary
- Python | Dictionary has_key()
- Python | Get key with maximum value in Dictionary
- Python | Convert a set into dictionary
- Iterate over a dictionary in Python
- Python Dictionary copy()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



