> Hm. What if list comprehensions returned a "lazy list", that if you took > an iterator of it, you'd get a generator-iterator, but if you tried to use > it as a list, it would populate itself? Then there'd be no need to ever > *not* use a listcomp, and only one syntax would be necessary. > > More specifically, if all you did with the list was iterate over it, and > then throw it away, it would never actually populate itself. The principle > drawback to this idea from a semantic viewpoint is that listcomps can be > done over expressions that have side-effects. :( I don't think this can be done without breaking b/w compatibility. Example: a = [x**2 for x in range(10)] for i in a: print i print a Your proposed semantics would throw away the values in the for loop, so what would it print in the third line? --Guido van Rossum (home page: http://www.python.org/~guido/)
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