Playback starts YouTube’s embedded player (privacy-enhanced mode).
How to get the key with the maximum value in a dictionary?
ChannelFinxter - Create Your Coding BusinessDescription from the creator
In short: use the max function with the key argument. It’s a simple but powerful solution to get the key from a dictionary with the highest value (maximum) – without using any library call:
~~~~
# Python Code
income = {'John' : 213000,
'Mary' : 23000,
'Alice' : 878000}
print(max(income, key=income.get))
# Alice
~~~~
Read the whole article with more examples and explanations:
blog.finxter.com/how-to-get-the-key-with-the-ma…
~~~~
Become a better coder! Download the 5x Python Cheat Sheet Course (PDF). It’s free!
*** Click: blog.finxter.com/subscribe/ ***
🐍 Cheating in Python? Of course! 🐍
See you soon -- it’s fun! 🤓
~~~~
A puzzle a day to learn, code, and play!
Finxter.com
Have a break. Get your "Coffee Break Python" book...
... THE PUZZLE-BASED LEARNING PYTHON BOOK!
blog.finxter.com/coffee-break-python/
About this tutorial
Finxter - Create Your Coding Business published this 2:37 video tutorial on October 25, 2019. It has been watched 11,855 times on YouTube.
- Category
- Education
- Duration
- 2:37
- Published
- October 25, 2019
- Views
- 11,855
- Likes
- 108
Tags
Share
Further reading
-
Get Key With Maximum Value in Dictionary in Python
tutorialdeep.com
The short answer is to use the Python max() function to find a key with a maximum value in Dictionary. Each key of the Dictionary may contain the elements with the numeric values. The elements are not arranged in sequen…
-
Python | Get key with maximum value in Dictionary - GeeksforGeeks
geeksforgeeks.org
Python | Get key with maximum value in Dictionary Last Updated: 18-05-2020. Given a dictionary, the task is to find the key having the maximum value. Examples :
-
Get key with maximum value in Dictionary in Python
tutorialspoint.com
Given Dictionary: {'Mon': 3, 'Tue': 11, 'Wed': 8} The Key with max value: Tue With itemgetter and max With itemgetter function we get the items of the dictionary and by indexing it to position one we get the values.
This tutorial in other languages
- FRComment obtenir la clé avec la valeur maximale dans un dictionnaire?
- ESCómo obtener la clave con el valor máximo en un diccionario?
- PTComo obter a chave com o valor máximo em um dicionário?
- ITCome ottenere la chiave con il valore massimo in un dizionario?
- DEWie die Taste mit dem Maximalwert in einem Wörterbuch zu bekommen?
- NLHoe de sleutel met de maximale waarde in een woordenboek te krijgen?
- RUКак получить ключ с максимальным значением в словаре?
- PLJak dostać klucz o wartości maksymalnej w słowniku?
- JA辞書内の最大値でキーを取得するには?
- ARكيفية الحصول على المفتاح مع قيمة الحد الأقصى في القاموس؟
- HIकैसे एक शब्दकोश में अधिकतम मूल्य के साथ कुंजी पाने के लिए?
- IDCara mendapatkan kunci dengan nilai maksimum dalam kamus?