title: Breaking from a loop in list comprehension in python
body: <p>I have a simple task of selecting all elements from a list (sorted in descending order) that lie above a given element.
  i.e.</p>
  
  <pre><code>X=[32,28,26,21,14,11,8,6,3]
  Threshold=12
  Result=[32,28,26,21,14]
  </code></pre>
  
  <p>What I did initially was something simple like</p>
  
  <pre><code>FullList=[x for x in FullList if x&gt;=Threshold]
  </code></pre>
  
  <p>However, since the list is sorted, I can (and need to) break in between.</p>
  
  <p>After much head banging and a beautiful tutorial <a href="http://tech.pro/tutorial/1554/four-tricks-for-comprehensions-in-python" rel="nofollow">here</a>, I finally came up with the following solution.</p>
  
  <pre><code> def stopIteration():
        raise StopIteration
  
   FullList=list(x if x&gt;=Threshold else stopIteration() for x in FullList )
  </code></pre>
  
  <p>However, when I write the following statement, it gives me a syntax error:</p>
  
  <pre><code>FullList=list(x if x&gt;=Threshold else raise StopIteration for x in FullList )
  </code></pre>
  
  <p>What is the reason behind this behaviour?</p>