3 ms·
Parenthetical comprehensions (generator expressions) are equivalent to your expanded function, but list comprehensions are not. `(x for x in range(10))` creates
by mplanchard 7y ago
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.
- Kwantuum 7y agoYou will notice that I explicitly unpacked the generator object in the brackets below the generator function by prefixing it with an asterisk.