On Mon, Jan 19, 2009 at 1:41 PM, Scott Dial
<scott+python-...@scottdial.com> wrote:
> Vitor Bosshard wrote:
>> Are you even sure the list comprehension doesn't already shortcut evaluation?
>
> It does not. The body of the comprehension is evaluated all the way to
> completion, ..

In addition, the test is evaluated on all items as well:

>>> def test(i):
...    print "testing", i
...    return i**2 < 10
...
>>> a = (i for i in range(10) if test(i))
>>> a.next()
testing 0
0
>>> a.next()
testing 1
1
>>> a.next()
testing 2
2
>>> a.next()
testing 3
3
>>> a.next()
testing 4
testing 5
testing 6
testing 7
testing 8
testing 9
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to