Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a dictionary of the structure like:

Python
{
{'A':123,
'B':{"QW":456, "RE":897, "_id" = "IRET"}
},
{'C':123,
'D':{"DE":56, "YE":87, "_id" = "REWQ"}
},
{'E':123,
'F':{"RT":432, "MN":7, "_id" = "AWER"}
}
}


I need to search this dict for '_id' == "AWER" while returning

Python
{'E':123,
'F':{"RT":432, "MN":7, "_id" = "AWER"}
}


What I have tried:

This is only for the first nest of the query.
lst = next(k,v for k,v in data[0].items() if v['E'] == '123')
Posted
Comments
Richard MacCutchan 9-Apr-18 6:28am    
I cannot get Python to accept that code, even changing the rogue equals signs to colons.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900