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, despite the fact that a.next() does not return until there is a successful test of the if expression. >>> def print_range(n): ... for i in range(n): ... print(i) ... yield i ... >>> a = (i for i in print_range(10) if i**2<10) >>> a.next() 0 0 >>> a.next() 1 1 >>> a.next() 2 2 >>> a.next() 3 3 >>> a.next() 4 5 6 7 8 9 Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration -- Scott Dial scott at scottdial.com scodial at cs.indiana.edu
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