How to take out a specific element from a symbol
This is my Code
[{‘symbol’: ‘LINKUSDT’, ‘orderId’: 3422916084, ‘orderListId’: -1, ‘clientOrderId’: ‘and_7e6da89c3092431b945316e541c48d78’, ‘price’: ‘7.37000000’, ‘origQty’: ‘1.62000000’, ‘executedQty’: ‘0.00000000’, ‘cummulativeQuoteQty’: ‘0.00000000’, ‘status’: ‘NEW’, ‘timeInForce’: ‘GTC’, ‘type’: ‘LIMIT’, ‘side’: ‘BUY’, ‘stopPrice’: ‘0.00000000’, ‘icebergQty’: ‘0.00000000’, ‘time’: 1654924767267, ‘updateTime’: 1654924767267, ‘isWorking’: True, ‘origQuoteOrderQty’: ‘0.00000000’}, {‘symbol’: ‘DOTUSDT’, ‘orderId’: 2973110534, ‘orderListId’: -1, ‘clientOrderId’: ‘and_7e13c97d76ee43d0a4445f05b87c7143’, ‘price’: ‘7.76000000’, ‘origQty’: ‘1.54000000’, ‘executedQty’: ‘0.00000000’, ‘cummulativeQuoteQty’: ‘0.00000000’, ‘status’: ‘NEW’, ‘timeInForce’: ‘GTC’, ‘type’: ‘LIMIT’, ‘side’: ‘BUY’, ‘stopPrice’: ‘0.00000000’, ‘icebergQty’: ‘0.00000000’, ‘time’: 1654925779775, ‘updateTime’: 1654925779775, ‘isWorking’: True, ‘origQuoteOrderQty’: ‘0.00000000’}
I Want to Print
LINKUSDT
DOTUSDT
>Solution :
You can do
x = [{'symbol': 'LINKUSDT', 'orderId': 3422916084, 'orderListId': -1, 'clientOrderId': 'and_7e6da89c3092431b945316e541c48d78', 'price': '7.37000000'}]
symbol = x[0].get('symbol')
We are first accessing the dictionary which is in the list. Afterwhich we are accessing the symbol key in the dictionary — we use a .get() to fetch the corresponding value.