PEP proposal: sequence expansion support for yield statement: yield *
Ethan Furman
ethan at stoneleaf.us
Wed Apr 20 16:01:35 EDT 2016
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
More information about the Python-list
mailing list