title: Get a sub-set of a Python dictionary
body: <p>I have a dictionary:</p>
  
  <pre><code>{'key1':1, 'key2':2, 'key3':3}
  </code></pre>
  
  <p>I need to pass a sub-set of that dictionary to third-party code. It only wants a dictionary containing keys <code>['key1', 'key2', 'key99']</code> and if it gets another key (eg <code>'key3'</code>), it explodes in a nasty mess. The code in question is out of my control so I'm left in a position where I have to clean my dictionary.</p>
  
  <p>What's the best, way to limit a dictionary to a set of keys?</p>
  
  <p>Given the example dictionary and allowed keys above, I want:</p>
  
  <pre><code>{'key1':1, 'key2':2}
  </code></pre>