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

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 :: pass integer by reference in Python 
Python :: how to set propee timeline in python 
Python :: how to add some thing in python list 
Python :: how to iterate a list in reverse order in python with index 
Python :: check if variable is defined in python 
Python :: sleep your computer python 
Python :: python collection 
Python :: python if not none in one line 
Python :: na.fill pyspark 
Python :: merge two arrays python 
Python :: python check if string is float 
Python :: keras.datasets no module 
Python :: is plaindrome python 
Python :: sftp python 
Python :: df to dict 
Python :: python startswith method 
Python :: What are Augmented Assignment Operators in python 
Python :: support vector machine example 
Python :: tkinter change button foreground 
Python :: pandas get attribute of object 
Python :: circle python programe 
Python :: add two dataframes together 
Python :: split function python 
Python :: how to open annaconda 
Python :: create 20 char with python 
Python :: max in python 
Python :: python write a line to a file 
Python :: python secret 
Python :: detect gender from name 
Python :: drf serializer 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =