[
{
"_id": "001",
"ca":
[
{
"car": "EM",
"ind": null,
"bindOnline": true,
"isEligible": false,
"nai": "111421",
"is": false,
"xId": "000501"
},
{
"cd": "xyz",
"i": null,
"bi": true,
"isEligible": true,
"naie": null,
"internalClassificationCd": "212266"
}
],
"states":
[
"A"
],
"s": "0005",
"x": ""
},
CodePudding user response:
To access the xId
value of a single dictionary (e.g. the one in first position) just run
xid = l[0]['ca'][0]['xId']
To access all xId
values contained in all dictionaries of your list and append them to another list
xids = []
for i in range(len(l)):
xids.append(l[i]['ca'][0]['xId'])
CodePudding user response:
for a single dictionary, to access xId value use this code
item[0]['ca'][0]['xId']
for access to all values use below one
xIds = [i['ca'][0]['xId'] for i in item]