[Python-Dev] Tricky way of of creating a generator via a comprehension expression

Serhiy Storchaka storchaka at gmail.com
Sat Nov 25 03:18:19 EST 2017


24.11.17 00:20, Greg Ewing пише:
> Serhiy Storchaka wrote:
>> Ivan explained that this function should be rough equivalent to
>>
>>    def f():
>>        t = [(yield i) for i in range(3)]
>>        return (x for x in t)
> 
> This seems useless to me. It turns a lazy iterator
> into an eager one, which is a gross violation of the
> author's intent in using a generator expression.

This is a *rough* equivalent. There are differences in details.



More information about the Python-Dev mailing list