title: Matching key/value pairs in two dictionaries and creating a third one
body: <p>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:</p>
  
  <pre><code>matched = {}
  for i in data1.keys():
      for j in data2.keys():
          if i in j:
              matched = {i: data1[i]}
          else:
              pass
  </code></pre>
  
  <p>When I run this snippet I get <em>matched</em> 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?</p>