Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to find the key with maximum value in a dictionary with Python

4 Answers

0 votes
import operator

dict = {'key1':34, 'key2':89, 'key3':12, 'key4':72}

max_key_value = max(dict.items(), key=operator.itemgetter(1))[0]

print(max_key_value)







'''
run:

key2

'''

 



answered Apr 10, 2021 by avibootz
0 votes
dict = {'key1':34, 'key2':89, 'key3':12, 'key4':72}
 
max_key_value = max(dict, key=lambda key: dict[key])
 
print(max_key_value)
 
 
 
 
 
 
'''
run:
 
key2
 
'''

 



answered Apr 10, 2021 by avibootz
edited Apr 10, 2021 by avibootz
0 votes
dict = {'key1':34, 'key2':89, 'key3':12, 'key4':72}
 
max_key_value = max(dict, key = dict.get)
 
print(max_key_value)
 
 
 
 
 
 
 
'''
run:
 
key2
 
'''

 



answered Apr 10, 2021 by avibootz
edited Apr 10, 2021 by avibootz
0 votes
import operator

dic = {'a':13, 'b':96, 'c':8, 'd':24, 'e':36, 'f':17}

mx = max(dic.items(), key=operator.itemgetter(1))

print(mx)




'''
run:

('b', 96)

'''

 



answered Mar 23, 2023 by avibootz
...