On Mon, Jan 19, 2009 at 1:41 PM, Scott Dial <scott+python-dev at 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4