List/Conditional Comprehension in Python
<p>I was wondering how to make the following into a comprehension:</p>

<pre><code>for g in a:
    for f in g[::3]:
        if f == clf.best_params_:
            print g
</code></pre>

<p>I tried this:</p>

<pre><code>p = [[print g for g in a] if f==clf.best_params for f in [g[::3] for g in a]]
p
</code></pre>

<p>but got an error at <code>for f in</code> </p>

<p>Would love some help! Thanks!</p>

<p>I think you've confused the construct: it's a <strong>list</strong> comprehension, not a macro of some sort.</p>

<p>You don't get this sort of side effect; the purpose of a list comprehension is to construct a list.</p>

python list scikit-learn conditional list-comprehension