HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

How to get the key with the maximum value in a dictionary?

11,855 views October 25, 2019 2:37

Watch on YouTube
ChannelFinxter - Create Your Coding Business

Description from the creator

I have spent my morning hours with an important mission: finding the cleanest, fastest, and most concise answer to this question. I realized that many answers on the web use libraries which is not necessary for this simple problem.

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

This tutorial in other languages