Post

PythonPython

s
sreelu 123

Posted on 26th April 2024|16 views

0
votes

Max Value In Dictionary Python

How to get a key with maximum value in python?

Answers
P
naseer mohammad

Posted on 26th April 2024

There are two simple methods to find a key with maximum value.

Method 1: using max() function

Sales = {'M.A.C':100, 'LAKME':1292, 'Maybelline' : 88}

Keymax = max(Sales, key=Sales.get)

print(Keymax)

Output:

LAKME

 

Method 2: using max() with lambda function

Sales = {'M.A.C':100, 'LAKME':1292, 'Maybelline' : 88}

Keymax = max(Sales, key= lambda x: Sales[x])

print(Keymax)

Output: 

LAKME

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos