Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 get min max value from a dictionary

d = {'A': 4,'B':10}
min_v = min(zip(d.values(), d.keys()))
# min_v is (4,'A')

max_v = max(zip(d.values(), d.keys()))
# max_v is (10,'B')
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

how to find min, max in dictionaries

# How to perform various calculations (min, max, sorting) in dict with .zip()
prices = {
'ACME': 45.23,
'AAPL': 612.78,
'IBM': 205.55,
'HPQ': 37.20,
'FB': 10.75
}

min_price = min(zip(prices.values(), prices.keys()))
max_price = max(zip(prices.values(), prices.keys()))
prices_sorted = sorted(zip(prices.values(), prices.keys()))
Comment

PREVIOUS NEXT
Code Example
Python :: space to underscore python 
Python :: linux command on python 
Python :: how to install python libraries 
Python :: number 1 
Python :: how to find mean of one column based on another column in python 
Python :: plotly hide trace from hover 
Python :: make a specific column a df index 
Python :: series to dataframe with column names 
Python :: append a line to a text file python 
Python :: pythom datetime now 
Python :: python list subdirectories 
Python :: rename a column in python 
Python :: Concatenate strings using Pandas groupby 
Python :: python previous answer 
Python :: sort array python by column 
Python :: creating virtual environment python 
Python :: python selenium save cookies 
Python :: all combination of params 
Python :: find duplicate in dataset python 
Python :: how to install python 2 
Python :: virtual environment flask 
Python :: python [a]*b means [a,a,...b times] v2 
Python :: find the determinant of a matrix in python 
Python :: matplotlib rc params 
Python :: does break stop all loops 
Python :: python convert remove spaces from beginning of string 
Python :: python extract thefile name from relative path 
Python :: python print unicode character 
Python :: how to check if index is out of range python 
Python :: python get nth letter of alphabet 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =