On Sun, Jan 14, 2018 at 3:01 PM, Peng Yu <pengyu...@gmail.com> wrote: > Hi, > > I see the following usage of list comprehension can generate a > generator. Does anybody know where this is documented? Thanks.
Here's the (a?) generator expression PEP: https://www.python.org/dev/peps/pep-0289/ Here's a presentation I put together on this and related topics a while back: http://stromberg.dnsalias.org/~strombrg/Intro-to-Python/Python%20Generators,%20Iterators%20and%20Comprehensions%202014.pdf FWIW, [a for a in range(2)] is a list comprehension; it's eager. And (a for a in range(2)) is a generator expression; it's lazy. HTH -- https://mail.python.org/mailman/listinfo/python-list