I have this sample return json:
message_response_json = {"details": [
{
"orderId": "1",
"accountId": "1",
"orderStatus": "CANCELED"
},
{
"orderId": "2",
"accountId": "1",
"orderStatus": "SETTLED"
},
{
"orderId": "3",
"accountId": "1",
"orderStatus": "FUNDED"
},
{
"orderId": "4",
"accountId": "1",
"orderStatus": "FUNDED"
},
]}
I want to only get the list of orderIds
with the orderStatus
"FUNDED"
. This is the code I have so far:
details = message_response_json['details']
results = list(filter(lambda detail: detail['orderStatus'].lower() == "funded", details))
print('results', results)
This is what's printing:
results [{'orderId': '3', 'accountId': '1', 'orderStatus': 'FUNDED'}, {'orderId': '4', 'accountId': '1', 'orderStatus': 'FUNDED'}]
But I only ever want to get something like:
results [{'orderId': '3'}, {'orderId': '4'}]
or
results ['3', '4']
Is there a built-in map
function that I can use in python?