Skip to content
Related Articles

Related Articles

Improve Article

Python | Get key with maximum value in Dictionary

  • Difficulty Level : Easy
  • Last Updated : 13 Oct, 2021
Geek Week

Given a dictionary, the task is to find the key having the maximum value. 
Examples : 
 

Input : {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88}
Output : Jaguar

Input:  {'Geeks':1900, 'for':1292, 'geek' : 88}
Output:  Geeks

 
Method #5: Using max() function
 

Python3




# Python code to find key with Maximum value in Dictionary
  
# Dictionary Initialization
Tv = {'BreakingBad':100, 'GameOfThrones':1292, 'TMKUC' : 88}
 
Keymax = max(zip(Tv.values(), Tv.keys()))[1]
print(Keymax)
Output: 
GameOfThrones

 

 
Method 2: Using max() with lambda function
 

Python3




# Python code to find key with Maximum value in Dictionary
  
# Dictionary Initialization
Tv = {'BreakingBad':100, 'GameOfThrones':1292, 'TMKUC' : 88}
 
Keymax = max(Tv, key= lambda x: Tv[x])
print(Keymax)
Output: 



GameOfThrones

 

  
Method 3: Using operator
 

Python3




# Python code to find key with
# Maximum value in Dictionary
import operator
 
# Dictionary Initialization
Car = {'Audi':100, 'BMW':1292, 'Jaguar': 210000, 'Hyundai' : 88}
 
# Getting max item
keyMax = max(Car.items(), key = operator.itemgetter(1))[0]
print(keyMax)
Output: 
Jaguar

 

  
Method 4: 
 

Python3




# Python code to find key with Maximum value in Dictionary
 
# Dictionary Initialization
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))])
Output: 
GFG

 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :