News for hackers. Stuff that matters.
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.
Re:WTFPython – Understanding Python through surprising snippets by Kwantuum on Monday December 23, 2019 @03:47PM (#21867219)
You will notice that I explicitly unpacked the generator object in the brackets below the generator function by prefixing it with an asterisk.