Posted on 16th September 2024|16 views
How to get a key with maximum value in python?
Posted on 16th September 2024| views
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