Reputation: 159
I have the following the function:
price = client.futures_recent_trades(symbol="BTCUSDT", limit=1)
of type <class 'list'>
that has output:
[{'id': 1644406868, 'price': '58024.69', 'qty': '0.009', 'quoteQty': '522.22', 'time': 1637262411652, 'isBuyerMaker': False}]
and:
I want to return price value only : 'price': '58024.69'
and therefore,
print(len(price))=1
but print(len(price[0]))= 6
But when I tried price[0][1]
, it throws an error list index out of range
Upvotes: 1
Views: 102
Reputation:
thisdict = dict(price)
x = thisdict.get("price")
print("price: " + x)
Upvotes: 0
Reputation: 144
It's a dictionary within a list, so you should pass the key for the second index, like shown below.
price[0]['price']
Upvotes: 3