我希望从下面的字典中获得最高的“最高”。
响应=
[
{
'timestamp':'2019-04-13T04:12:00.000Z',
'symbol':'XBTUSD',
'open':5065,
'high':5067,
'low':5065.5,
'close':5066.5,
'trades':13,
'volume':10002,
'vwap':5066.8829,
'lastSize':2,
'turnover':197408849,
'homeNotional':1.9740884899999998,
'foreignNotional':10002
},
{
'timestamp':'2019-04-13T04:11:00.000Z',
'symbol':'XBTUSD',
'open':5065,
'high':5065,
'low':5065,
'close':5065,
'trades':0,
'volume':0,
'vwap':None,
'lastSize':None,
'turnover':0,
'homeNotional':0,
'foreignNotional':0
},
{
'timestamp':'2019-04-13T04:10:00.000Z',
'symbol':'XBTUSD',
'open':5065,
'high':5065,
'low':5065,
'close':5065,
'trades':2,
'volume':2000,
'vwap':5065,
'lastSize':397,
'turnover':39486000,
'homeNotional':0.39486,
'foreignNotional':2000
}
]
然后打印所有“高”字:
for h in response:
print (h['high'])
哪些打印:
5067
5065
5065
然后出现一个问题,如何从数字列表中获得最大值?在这种情况下,它将是“ 5067”。我尝试使用max方法,但无济于事。
(max(h['high']))
不起作用。 最佳答案
使用itemgetter
和key
参数:
from operator import itemgetter
max(h, key=itemgetter('high'))