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 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 :: python randomized selection 
Python :: interpoltaion search formula python 
Python :: len table python 
Python :: python join generators 
Python :: python day from date 
Python :: python read file without newline 
Python :: python print range 
Python :: acess nvidia from docker compose 
Python :: create pickle file python 
Python :: pandas read_csv random rows 
Python :: django migrate using db 
Python :: remove unnamed column pandas 
Python :: pandas drop values from column 
Python :: how to add two different times in python 
Python :: python random email generator 
Python :: python requests.get pdf An appropriate representation of the requested resource could not be found 
Python :: how to add input box in tkinter 
Python :: matplotlib latex non italic indices 
Python :: img read 
Python :: python load pandas from pickle 
Python :: creating an interface tkinter 
Python :: change py version in colab 
Python :: pandas lambda if else 
Python :: easy sending email python 
Python :: djangodebug toolbar not showing 
Python :: python - subset specific columns name in a dataframe 
Python :: create empty csv file in python 
Python :: python input. yes or no 
Python :: how to create file using python cat command 
Python :: remove every file that ends with extension in python 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =