Python | Get key with maximum value in Dictionary
Given a dictionary, the task is to find the key having maximum value.
Examples :
Input : {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88}
Output : Jaguar
Input: {'Geeks':1900, 'for':1292, 'geek' : 88}
Output: Geeks
Method #1 : Using max() function
# Python code to find key with Maximum value in Dictionary # Dictionary Intialisation Tv = {'BreakingBad':100, 'GameOfThrones':1292, 'TMKUC' : 88} Keymax = max(Tv, key=Tv.get) print(Keymax) |
chevron_right
filter_none
Output:
GameOfThrones
Method #2: Using operator
# Python code to find key with # Maximum value in Dictionary import operator # Dictionary Intialisation Car = {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88} # Getting max item keyMax = max(Car.items(), key = operator.itemgetter(1))[0] print(keyMax) |
chevron_right
filter_none
Output:
Jaguar
Method #3 :
# Python code to find key with Maximum value in Dictionary # Dictionary Intialisation Company = {'GFG':10000, 'Hashd':2292, 'Infy': 200} # taking list of car values in v v = list(Company.values()) # taking list of car keys in v k = list(Company.keys()) print(k[v.index(max(v))]) |
chevron_right
filter_none
Output:
GFG
Recommended Posts:
- Python program to find second maximum value in Dictionary
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert nested dictionary into flattened dictionary
- Python | Convert string dictionary to dictionary
- Python | Get key from value in Dictionary
- Python Dictionary
- Python Dictionary copy()
- Python | Key index in Dictionary
- Iterate over a dictionary in Python
- Python | Nested Dictionary
- Second largest value in a Python Dictionary
- Python Dictionary Comprehension
- Add a key:value pair to dictionary in Python
- Python | Transcribing dictionary key
- Python | Accessing Key-value 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 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.



