Re:WTFPython – Understanding Python through surprising snippets
by mplanchard on Monday December 23, 2019 @09:14AM
(#21863684)
Parenthetical comprehensions (generator expressions) are equivalent to your expanded function, but list comprehensions are not. `(x for x in range(10))` creates a generator, but using square brackets converts it to a list, including allocating the necessary memory. If you’re trying to do yield and streaming, the parens will serve you better.
[ Parent
| on HN ]