title: Python for element in list matching condition
body: <p>I have found myself frequently iterating over a subset of a list according to some condition that is only needed for that loop, and would like to know if there is a more efficient way to write this.</p>
  <p>Take for example the list:</p>
  <p><code>foo = [1, 2, 3, 4, 5]</code></p>
  <p>If I wanted to build a for loop that iterates through every element greater than 2, I would typically do something like this:</p>
  <pre><code>for x in [y for y in foo if y &gt; 2]:
      # Do something
  </code></pre>
  <p>However this seems redundant, and isn't extremely readable in my opinion. I don't think it is particularly inefficient, especially when using a generator instead as @iota pointed out below, however I would much rather be able to write something like:</p>
  <pre><code>for x in foo if x &gt; 2:
      # Do something
  </code></pre>
  <p>Ideally avoiding the need for a second <code>for</code> and a whole other temporary variable. Is there a syntax for this? I use Python3 but I assume any such syntax would likely have a Python2 variant as well.</p>
  <p>Note: This is obviously a very simple example that could be better handled by something like <code>range()</code> or sorting &amp; slicing, so assume foo is any arbitrary list that must be filtered by any arbitrary condition</p>