Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python find max in list of dict by value

lst = [{'price': 99, 'barcode': '2342355'}, {'price': 88, 'barcode': '2345566'}]

maxPricedItem = max(lst, key=lambda x:x['price'])
minPricedItem = min(lst, key=lambda x:x['price'])
Comment

max of a dict

dic={0: 1.4984074067880424, 1: 1.0984074067880423, 2: 1.8984074067880425, 3: 2.2984074067880425, 4: 2.2984074067880425}
max_value = max(dic.values())  # maximum value
max_keys = [k for k, v in dic.items() if v == max_value] # getting all keys containing the `maximum`

print(max_value, max_keys)
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

get max n values in dict py

import heapq
from operator import itemgetter

n = 3

items = {'a': 7, 'b': 12, 'c': 9, 'd': 0, 'e': 24, 'f': 10, 'g': 24}

topitems = heapq.nlargest(n, items.items(), key=itemgetter(1))  # Use .iteritems() on Py2
topitemsasdict = dict(topitems)
Comment

max element in dictionary python

import operator
stats = {'a':1000, 'b':3000, 'c': 100}
max(stats.iteritems(), key=operator.itemgetter(1))[0]
Comment

PREVIOUS NEXT
Code Example
Python :: how to make a complex calculator in python 
Python :: python read music stream 
Python :: append a line to a text file python 
Python :: playsound 
Python :: python loop through list 
Python :: all characters python 
Python :: error bar plot python 
Python :: python square root 
Python :: get values using iloc 
Python :: scikit learn split data set 
Python :: extract link from text python 
Python :: python print 
Python :: all alphabets 
Python :: panda dataframe read csv change string to float 
Python :: django models distinct 
Python :: remove n from string python 
Python :: on message discord py 
Python :: dataframe delete row 
Python :: virtual environment flask 
Python :: convert set to list python time complexity 
Python :: how to compare current date to future date pythono 
Python :: connecting google colab to local runtime 
Python :: from sklearn.externals import joblib instead use..... 
Python :: python ls directory 
Python :: how to swap tuple 
Python :: calculate integral python 
Python :: libreoffice add row at the end of table 
Python :: find allurl in text python 
Python :: how to address a column in a 2d array python 
Python :: pandas group by count 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =