Dictionaries in Python is same as Associative arrays or Maps in other languages. Unlike lists, dictionaries stores data in
Let’s see how to find the second maximum value in a Python dictionary.
Method #1: Naive Approach:
A general approach is to find the largest value of the dictionary and then iterate over the dictionary maintaining the value that must be greater than all the other values and less than the maximum value.
Method #2: Using sorted() method
We can find the second largest value in a dictionary by sorting the values of the dictionaries and then retrieving the second last element from the sorted list.
example_dict.values() gives list of all the values in the dictionary.
sorted() method will sort the list of
dict_values to list and return the second last element of the sorted list, i.e. the second largest value of dictionary.
- Python program to find the sum of all items in a dictionary
- Python program to find the highest 3 values in a dictionary
- Python | Get key with maximum value in Dictionary
- Python - Extract ith Key's Value of K's Maximum value dictionary
- Python - Maximum Value in Nested Dictionary
- Python - Maximum record value key in dictionary
- Python - Column Maximum in Dictionary Value Matrix
- Python - Maximum of filtered Keys in dictionary
- Python - Maximum value assignment in Nested Dictionary
- Python program to create a dictionary from a string
- Python program to Swap Keys and Values in Dictionary
- Python program to print the dictionary in table format
- Find the size of a Dictionary in Python
- Python | Find the closest Key in dictionary
- Python | Find depth of a dictionary
- Python | Find Symmetric Pairs in dictionary
- Python | Find dictionary matching value in list
- Program to print all distinct elements of a given integer array in Python | Ordered Dictionary
- Dictionary and counter in Python to find winner of election
- Python - Find Keys with specific suffix in Dictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.