title: Remove keys from object not in a list in python?
body: <p>I have these keys:</p>
  
  <pre><code>keep = ["a","c"]
  </code></pre>
  
  <p>My dict:</p>
  
  <pre><code>testdict = {'
  'a':'vala',
  'b':'valb',
  'c':'valc',
  'd':'vald'
  }
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>testdict = {
  'a':'vala',
  'c':'valc'
  }
  </code></pre>
  
  <p>I want to remove all keys that do not match the key in the list.
  What is the fastest way to do this?</p>
  
  <p>I tried:</p>
  
  <pre><code>for key, value in testdict.iteritems():
        if key not in keep:
           del testdict[key]
  </code></pre>
  
  <p>But the above gives me errors since the size is changing. </p>