How To Get The Max Value Out Of List
I am looking to get the highest 'high' out of the dict below. Response = [ { 'timestamp':'2019-04-13T04:12:00.000Z', 'symbol':'XBTUSD', 'o
Solution 1:
Use itemgetter
and the key
parameter:
from operator import itemgetter
max(h, key=itemgetter('high'))
Solution 2:
max(iterable, *[, key, default]) - Return the largest item in an iterable or the largest of two or more arguments.
b=max(a, key=lambda x:x['high'])
print(b['high'])
Solution 3:
You can use a list comprehension to obtain all the values from the high
key then use the max()
function to get the maximum
maximum = max([h['high'] for h in response])
print(maximum)
5067
Post a Comment for "How To Get The Max Value Out Of List"