How to copy dictionaries with matching values for a given key from list to new list?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5762643/copy-dictionaries-with-matching-values-for-a-given-key">Copy dictionaries with matching values for a given key</a>  </p>
</blockquote>



<p>With an interface like <code>a = copyf(dictlist, key, valuelist)</code>.</p>

<pre><code>&gt;&gt;&gt; dictlist = [{'first': 'James',
                 'last': 'Joule'},
                {'first': 'James',
                 'last': 'Watt'},
                {'first': 'Christian',
                 'last': 'Doppler'}]
&gt;&gt;&gt; valuelist = ['James', 'John']
&gt;&gt;&gt; x = copyf(dictlist, 'first', valuelist)
&gt;&gt;&gt; print(x)
[{'first': 'James',
  'last': 'Joule'},
 {'first': 'James',
  'last': 'Watt'}]
</code></pre>

<p>The <code>dictlist</code> is effectively a <code>csv.DictReader</code> instance.</p>
