how to apply BREAK for Itertools count in List Comprehensions?
<p>if this is duplicate, already answered then sorry, i didn't came across this question </p>

<p>as i was reading itertools count, generating an iterator using for loop is easy, and i was trying to do that in list comprehension but i am facing this problem</p>

<pre><code>from itertools import *
</code></pre>

<p>by using for loop</p>

<pre><code>for x in itertools.count(5,2):
    if x &gt; 20:
        break
    else: 
        print(x)
5
7
9
11
13
15
17
19
</code></pre>

<p>i tried to do this in list comprehension</p>

<pre><code>[x if x&lt;20 else break for x in count(5,2)]
  File "&lt;ipython-input-9-436737c82775&gt;", line 1
    [x if x&lt;20 else break for x in count(5,2)]
                    ^
SyntaxError: invalid syntax
</code></pre>

<p>i tried with islice method and i got the answer</p>

<pre><code>[x for x in itertools.islice(itertools.count(5),10)]
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
</code></pre>

<p>without using islice method, how can I exit(using break or any thing) by using only count method?</p>

<p>additionally how to implement <code>break</code> in <code>list comprehensions</code>?</p>