title: Create a Python dictionary containing specific key–value pairs from another dictionary
body: <p>I have some code that looks something like this:</p>
  
  <pre><code>d = {'foo': True, 'bar': 42, 'baz': '!'}
  
  a = {'foo': d['foo'], 'bar': d['bar']}
  b = {'foo': d['foo'], 'baz': d['baz']}
  c = {'bar': d['bar'], 'baz': d['baz']}
  </code></pre>
  
  <p>Surely there's a better way to express this. I actually read the docs in the hope that a dictionary's <code>copy</code> method accepts keys to be included in the new dictionary:</p>
  
  <pre><code># I'd hoped that something like this would work...
  a = d.copy('foo', 'bar')
  b = d.copy('foo', 'baz')
  c = d.copy('bar', 'baz')
  </code></pre>
  
  <p>I could write a function for this purpose:</p>
  
  <pre><code>copydict = lambda dct, *keys: {key: dct[key] for key in keys}
  
  a = copydict(d, 'foo', 'bar')
  b = copydict(d, 'foo', 'baz')
  c = copydict(d, 'bar', 'baz')
  </code></pre>
  
  <p>Is there a better solution than the above?</p>