I have read two files from which I created dictionaries with IDs and their corresponding sequences as keys and values, respectively. I am trying to find the key/value pairs that exist in both dictionaries and to create a new one containing only these matching ones. Each dictionary has a couple thousand key/value pairs. My code is as follows:
matched = {}
for i in data1.keys():
for j in data2.keys():
if i in j:
matched = {i: data1[i]}
else:
pass
When I run this snippet I get matched with a single key/value pair, however I have counted the matching keys (and therefore values) between the two dicts and they are 2434. Does anybody know how to fix this?