Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107423

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

From Ethan Furman <ethan@stoneleaf.us>
Newsgroups comp.lang.python
Subject Re: PEP proposal: sequence expansion support for yield statement: yield *
Date 2016-04-20 13:01 -0700
Message-ID <mailman.38.1461182430.12923.python-list@python.org> (permalink)
References <573e61523bfc412ca8674b06d70f2fd7@sraex01sc.sisa.samsung.com> <5717E01F.3020804@stoneleaf.us>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: PEP proposal: sequence expansion support for yield statement: yield * Ethan Furman <ethan@stoneleaf.us> - 2016-04-20 13:01 -0700
  Re: PEP proposal: sequence expansion support for yield statement: yield * kenseehart@gmail.com - 2016-04-20 15:26 -0700
    Re: PEP proposal: sequence expansion support for yield statement: yield * Chris Angelico <rosuav@gmail.com> - 2016-04-21 09:23 +1000

csiph-web