I want to perform searches on values in a list of nested dictionaries and return another key:value pairs. These dictionaries are metafiles. Basically I want to search the ID of each dictionary, find all dictionaries that have the same ID, and return the file location (key:value) pairs.
metafile = [{'metadata':{'Title':'The Sun Also Rises', 'ID': 'BAY121-F1164EAB499'}, 'content': 'xyz', 'File_Path': 'file_location1'},
{'metadata':{'Title':'Of Mice and Men', 'ID': '499B0BAB@dfg'}, 'content': 'abc', 'File_Path': 'file_location2'},
{'metadata':{'Title':'The Sun Also Rises Review', 'ID': 'BAY121-F1164EAB499'}, 'content': 'ftw', 'File_Path': 'file_location3'}]
I created a loop to perform my search as follows. It returns an empty list though, how should I modify this so that the file paths are returned?
search_ID = 'BAY121-F1164EAB499'
path =[]
for a in metafile:
for val in a['metadata']['ID']:
if search_ID == val:
path.append(a['File_Path'])