Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python find the key with max value

a_dictionary = {"a": 1, "b": 2, "c": 3}

# get key with max value
max_key = max(a_dictionary, key=a_dictionary.get)

print(max_key)
Comment

python get the key with the max or min value in a dictionary

# Basic syntax:
key_with_max_value = max(dictionary, key=dictionary.get)

# Note, to get the max value itself, you can do either of the following:
max_value = dictionary[max(dictionary, key=dictionary.get)]
max_value = max(dictionary.values())

# Example usage:
dictionary = {"a": 1, "b": 2, "c": 3}
max(dictionary, key=dictionary.get)
--> 'c'
Comment

python max key dictionary key getter

from operator import itemgetter

items = [
    {'a': 1, 'b': 99},
    {'a': 2, 'b': 88},
    {'a': 3, 'b': 77},
]

print(max(items, key=itemgetter('a')))
print(max(items, key=itemgetter('b')))
Comment

PREVIOUS NEXT
Code Example
Python :: python ordereddict reverse 
Python :: k choose n python 
Python :: split string by spaces python 
Python :: python access global variable 
Python :: python count code, Count number of occurrences of a given substring 
Python :: how to remove all 2 in a list python 
Python :: Using python permutations function on a list 
Python :: how to plot confusion matrix 
Python :: count list python 
Python :: pandas where 
Python :: python sort class by attribute 
Python :: how to round in python 
Python :: convert python float list to 2 digit 
Python :: selenium firefox webdriver 
Python :: python series to list of string 
Python :: python file open try except error 
Python :: python expressions 
Python :: how to calculate z score in python 
Python :: find the index of a character in a string python 
Python :: python move a file from one folder to another 
Python :: plot multiple axes matplotlib 
Python :: return max value in groupby pyspark 
Python :: python extract zip file without directory structure 
Python :: find the highest 3 values in a dictionary. 
Python :: django python base 64 decode 
Python :: how yo import python lib 
Python :: Python datetime to string using strftime() 
Python :: cross join pandas 
Python :: python http request params 
Python :: decode multipart/form-data python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =