I would like to print only objects that contain USDT from:
requestT = requests.get('https://api1.binance.com/api/v3/ticker/price')
json_data = json.loads(requestT.text)
print(json_data)
Example:
data = [{'symbol': 'BNBETH', 'price': '0.16540000'}, {'symbol': 'BTCUSDT', 'price': '64321.11000000'}, {'symbol': 'ETHUSDT', 'price': '3330.76000000'}]
Result:
data1 = [{'symbol': 'BTCUSDT', 'price': '64321.11000000'}, {'symbol': 'ETHUSDT', 'price': '3330.76000000'}]
3
Answers
You can filter the data for example with list-comprehension:
Prints:
Always ensure that your HTTP request succeeded before trying to do anything with the response.
You could use a lambda for this but my preference is a discrete function.
So…
based on your hoped for result, I wrote a fairly simple solution, where I create a new list containing the matches inside it, in the code I also commented the various steps for a better understanding, obviously there are many ways to obtain the same result, this method is the most basic
Code.py
result:
I hope I have been of help to you.