<p>The Python list comprehension syntax makes it easy to filter values within a comprehension.  For example:</p>

<pre><code>result = [x**2 for x in mylist if type(x) is int]
</code></pre>

<p>Will return a list of the squares of integers in mylist.  However, what if the test involves some (costly) computation and you want to filter on the result?  One option is:</p>

<pre><code>result = [expensive(x) for x in mylist if expensive(x)]
</code></pre>

<p>This will result in a list of non-"false" expensive(x) values, however expensive() is called twice for each x.  Is there a comprehension syntax that allows you to do this test while only calling expensive once per x?</p>

Came up with my own answer after a minute of thought.  It can be done with nested comprehensions:
```
```
result = [y for y in (expensive(x) for x in mylist) if y]
```
```
I guess that works, though I find nested comprehensions are only marginally readable