I am stuck with the below issue where I am trying to search for specific value
in a nested dictionary inside of a nested list. It doesn't have to completely match but more like contains
. Below is the example data
data=[[{'A': 'test1'}, {'A': 'test2'}, {'BB': {'A': '111testabc'}}],
[{'A': 'test1'}, {'A': 'test3'}, {'BB': {'A': '999000abc'}}],
[{'A': 'test1'}, {'A': 'test4'}, {'BB': {'A': '99111testabc123'}}],
[{'A': 'test1'}, {'A': 'test5'}, {'BB': {'A': '123456abc'}}]]
I want to extract all the nested list including dictionary. The serach string is 111testabc
. So my expected output would be
[[{'A': 'test1'}, {'A': 'test2'}, {'BB': {'A': '111testabc'}}],
[{'A': 'test1'}, {'A': 'test4'}, {'BB': {'A': '99111testabc123'}}]]
I am trying to solve this with:
key, value = 'A', '111testabc'
for lp in data:
dictList.append([myDict for myDict in lp if myDict.get(key) in value])
Can anyone please let me know how to resolve this? I am using python3.9