[Python-ideas] Using yield inside a comprehension.

Andrew Barnert abarnert at yahoo.com
Tue Nov 26 18:31:26 CET 2013


On Nov 26, 2013, at 7:33, Jonathan Slenders <jonathan at slenders.be> wrote:

> What I tried to do, with my knowledge of Python 2 generators, is the following, but that doesn't work.
> 
> @coroutine
> def process(futures, func):
>     return [ func((yield from f)) for f in futures ]
> 
> They are also not equivalent. Using gather(), we have to wait before all the futures are ready, while in the second example, we could start creating the list on the fly. (Note that in this case "yield" instead of "yield from" would also work.)

What would be the benefit of starting to create the list on the fly? You can't actually do anything with it, or even see it from any code, until it's completed.


More information about the Python-ideas mailing list