On 22/02/20 11:45 am, Andrew Barnert via Python-ideas wrote:
there’s no reason you can’t write `[(yield None) for _ in range(3)]` to gather 
the first three values sent into your generator

Currently this doesn't quite do what you might expect.
It doesn't make the enclosing function into a generator,
it make the list comprehension itself a generator:

>>> def f():
...  return [(yield x) for x in range(10)]
...
>>> g = f()
>>> g
<generator object f.<locals>.<listcomp> at 0x6b396c>
>>>

I don't think this behaviour is deliberate; it seems to
be a consequence of deciding to compile the body of the
comprehension as a nested function.

--
Greg
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UXTVMCZI7SUSNYY4AP4MWXJ2RXOLQR2C/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to