Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python how to find the highest number in a dictionary

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

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


print(max_key)
Comment

get highest value from dictionary python

ages = {'Matt' : 30, 'Katie': 29, 'Nik': 31, 'Jack': 43}

#get the max value in Python dict
max_value = max(ages.values())
print(max_value)
#get the key for a dicts max value
max_key = max(ages, key=ages.get)
print(max_key)
        
Comment

find the max value in dictionary python

my_dict = {'a': 5, 'b': 10, 'c': 6, 'd': 12, 'e': 7}
max(my_dict, key=my_dict.get) # returns 'd'
Comment

find the highest 3 values in a dictionary.

from collections import Counter
# Initial Dictionary
my_dict = {'t': 3, 'u': 4, 't': 6, 'o': 5, 'r': 21}
k = Counter(my_dict)
# Finding 3 highest values
high = k.most_common(3)
print("Dictionary with 3 highest values:")
print("Keys: Values")
for i in high:
   print(i[0]," :",i[1]," ")
Comment

find the highest 3 values in a dictionary.

>>> sorted(my_dict, key=my_dict.get, reverse=True)[:3]
['K', 'B', 'A']
Comment

PREVIOUS NEXT
Code Example
Python :: fibonacci series python recursion 
Python :: python create a list of alphabets 
Python :: python split path at level 
Python :: dice simulator in python 
Python :: python check if folder is empty 
Python :: favicon django 
Python :: python random randint except a number 
Python :: python access index in for loop 
Python :: python print float in scientific notation 
Python :: tensot to numpy pytorch 
Python :: install pandas in python mac 
Python :: pandas determine percentage of nans in column 
Python :: mongodb between two values 
Python :: pandas convert to 2 digits decimal 
Python :: discord.py commands not working 
Python :: install wxpython 
Python :: dropdown in tkinter 
Python :: remove nan from list python 
Python :: filter with different operator in django 
Python :: list to csv pandas 
Python :: how to play sound after pressing a button in tkinter 
Python :: how to clear console in repl.it python 
Python :: pip install chatterbot 
Python :: python choose random sample from list 
Python :: os.execl(sys.executable, sys.executable, *sys.argv) 
Python :: python name of current file 
Python :: series datetime64 seconds to 0 
Python :: how to plot two columns graphs in python 
Python :: python plot lines with dots 
Python :: pandas remove index column when saving to csv 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =