PEP proposal: sequence expansion support for yield statement: yield *

kenseehart at gmail.com kenseehart at gmail.com
Wed Apr 20 18:26:31 EDT 2016


On Wednesday, April 20, 2016 at 1:00:45 PM UTC-7, Ethan Furman wrote:
> On 04/20/2016 12:34 PM, Ken Seehart wrote:
> 
> New ideas for Python are typically vetted on Python Ideas. [1]
> 
> > Currently the common pattern for yielding the elements in a sequence
>  > is as follows:
> >
> >    for x in sequence: yield x
> >
> > I propose the following replacement (the result would be identical):
> >
> >    yield *sequence
> >
> > The semantics are somewhat different from argument expansion (from
>  > which the syntax is borrowed), but intuitive: yield all of the elements
>  > of a sequence (as opposed to yield the sequence as a single item).
> 
> Your examples do not make clear what your result should be.  If you mean 
> the results are exactly the same you can get that behavior with
> 
>      yield from iter(x)
> 
> which, while being slightly longer, has the advantage of already 
> working.  ;)
> 
> --
> ~Ethan~
> 
> [1] https://mail.python.org/mailman/listinfo/python-ideas

To be clear, the comment "...(the result would be identical)" is indicative that the result would be identical, meaning "exactly the same".

Anyway, thanks for the link. And I suppose checking Python 3 for implementation would be a good prior step as well! Sadly, "yield from" is not in python 2.7, but it's presence in python 3.3 renders my proposal dead as a parrot without a liver.

Regards,
Ken



More information about the Python-list mailing list