title: How to execute a filter by function return value in list comprehension?
body: <p>Below is the basic logic: </p>
  
  <pre><code>result = []
  
  for item in item_lst:
      code = foo(item)
      if code != -1:
          result.append(code)
  </code></pre>
  
  <p>With list comprehension, I should write twice:</p>
  
  <pre><code>result = [foo(item) for item in item_lst]
  result = [code for code in result if code != -1]
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>result = [foo(item) for item in item_lst if foo(item) != -1]
  </code></pre>
  
  <p>Which will call function foo twice.</p>
  
  <p>Is there any better solutions?</p>