title: Is it possible to add a where clause with list comprehension?
body: <p>Consider the following list comprehension</p>
  
  <pre><code>[ (x,f(x)) for x in iterable if f(x) ]
  </code></pre>
  
  <p>This filters the iterable based a condition <code>f</code> and returns the pairs of <code>x,f(x)</code>. The problem with this approach is <code>f(x)</code> is calculated twice.
  It would be great if we could write like</p>
  
  <pre><code>[ (x,fx) for x in iterable if fx where fx = f(x) ]
  or
  [ (x,fx) for x in iterable if fx with f(x) as fx ]
  </code></pre>
  
  <p>But in python we have to write using nested comprehensions to avoid duplicate call to f(x) and it makes the comprehension look less clear</p>
  
  <pre><code>[ (x,fx) for x,fx in ( (y,f(y) for y in iterable ) if fx ]
  </code></pre>
  
  <p>Is there any other way to make it more pythonic and readable?</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>Coming soon in python 3.8! <a href="https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics" rel="noreferrer">PEP</a></p>
  
  <pre><code># Share a subexpression between a comprehension filter clause and its output
  filtered_data = [y for x in data if (y := f(x)) is not None]
  </code></pre>