我有一个嵌套列表,需要根据条件筛选出一个键/值
名单如下:
[{'buyer': False,
'commission': '0.01333920',
'commissionAsset': 'USDT',
'id': 52549382,
'maker': False,
'marginAsset': 'USDT',
'orderId': 2448678953,
'positionSide': 'BOTH',
'price': '3334.80',
'qty': '0.010',
'quoteQty': '33.34800',
'realizedPnl': '0',
'side': 'SELL',
'symbol': 'MKRUSDT',
'time': 1628311810877},
{'buyer': True,
'commission': '0.01334440',
'commissionAsset': 'USDT',
'id': 52544760,
'maker': False,
'marginAsset': 'USDT',
'orderId': 2447909783,
'positionSide': 'BOTH',
'price': '3336.10',
'qty': '0.010',
'quoteQty': '33.36100',
'realizedPnl': '-0.29400000',
'side': 'BUY',
'symbol': 'MKRUSDT',
'time': 1628309268672},
{'buyer': False,
'commission': '0.01322680',
'commissionAsset': 'USDT',
'id': 52532126,
'maker': False,
'marginAsset': 'USDT',
'orderId': 2447909485,
'positionSide': 'BOTH',
'price': '3306.70',
'qty': '0.010',
'quoteQty': '33.06700',
'realizedPnl': '0',
'side': 'SELL',
'symbol': 'MKRUSDT',
'time': 1628301912771},
{'buyer': True,
'commission': '0.01319760',
'commissionAsset': 'USDT',
'id': 52525468,
'maker': False,
'marginAsset': 'USDT',
'orderId': 2447502727,
'positionSide': 'BOTH',
'price': '3299.40',
'qty': '0.010',
'quoteQty': '32.99400',
'realizedPnl': '-0.29700000',
'side': 'BUY',
'symbol': 'MKRUSDT',
'time': 1628297857042},
现在,如何获得嵌套块的'time'值,其中'id'等于52532126?虽然我更喜欢矢量化,但我尝试遍历列表,但没有成功
for item in response_tradelist:
if item == '52532126':
print('ok')
即使它可以工作,我如何获得相应块中的“时间”值
由于您的id值在该字典块中是整数,因此无法使用字符串值进行检查, 您需要检查像item['id']==52532126这样的值
如果你想把整本字典都印出来
这是一个字典列表,您必须与每个项目中的
id
进行比较,然后如果id
匹配,则打印time
另外
id
值不是字符串,所以不要在id
周围使用引号试试这个:
如果要打印id为52532126的词典:
如果您特别需要时间,请将
print(dic)
替换为:相关问题 更多 >
编程相关推荐