How to dynamically pass predicates to filter function?
<p>I have a dictionary named <code>eval_params</code> that looks like this:</p>

<pre><code>In [1]: eval_params
Out[1]: 
{1: {'CLF': 'EMNB',
  'EM': 'False',
  'FEA': 'words',
  'NGRAM': '1-1',
  'PDS': 'T',
  'PSE': '-',
  'RN': '1dnf',
  'STEM': 'False',
  'UDS': 'He'},
 2: {'CLF': 'EMNB',
  'EM': 'False',
  'FEA': 'words',
  'NGRAM': '1-1',
  'PDS': 'TS',
  'PSE': '-',
  'RN': '1dnf',
  'STEM': 'False',
  'UDS': 'He'},
 3: {'CLF': 'EMNB',
  'EM': 'False',
  'FEA': 'words',
  'NGRAM': '1-1',
  'PDS': 'T',
  'PSE': '-',
  'RN': '1dnf',
  'STEM': 'False',
  'UDS': 'Te'}}
</code></pre>

<p>I have to filter this dictionary by certain predicates for which I use the built-in function <code>filter</code>:</p>

<pre><code>In [2]: filter(pred_func, eval_params.iteritems())
Out[2]: 
[(3,
  {'CLF': 'EMNB',
   'EM': 'False',
   'FEA': 'words',
   'NGRAM': '1-1',
   'PDS': 'T',
   'PSE': '-',
   'RN': '1dnf',
   'STEM': 'False',
   'UDS': 'Te'})]    
</code></pre>

<p>My problem is that I don't want to hard-code the predicates inside <code>pred_func</code> but to pass them dynamically to <code>pred_func</code>. The current <code>pred_func</code> looks like this:</p>

<pre><code>def pred_func((i, d)):
    # I have to hard-code the parameters to filter by. I don't want that
    return d['PDS'] == 'T' and d['UDS'] = 'Te'
</code></pre>

<p>Instead, I'd like to have something like:</p>

<pre><code>def pred_func((i, d), predicates):
    vals = []
    # predicates would be a dictionary such as {'PDS':'T', 'UDS':'Te'}
    for param, val in predicates.iteritems():
        vals.append(d[param] == val)
    return all(vals)
</code></pre>

<p>However, as far as I know, I cannot pass extra arguments to the predicate function, so how can I accomplish what I want in an elegant way? Any idea?</p>
