Here's an interesting idea regarding yield **x:

Right now a function containing any yield returns a generator.  Therefore,
it works like a generator expression, which is the lazy version of a list
display.  lists can only contain elements x and unpackings *x.  Therefore,
it would make sense to only have "yield x" and "yield *xs" (currently
spelled "yield from xs")

If one day, there was a motivation to provide a lazy version of a dict
display, then such a function would probably have "yield key: value" or
"yield **d".   Such a lazy dictionary is the map stage of the famous
mapreduce algorithm.  It might not make sense in single processor python,
but it might in distributed Python.



On Fri, Oct 14, 2016 at 3:34 AM Sjoerd Job Postmus <>

> On Fri, Oct 14, 2016 at 07:06:12PM +1300, Greg Ewing wrote:
> > Sjoerd Job Postmus wrote:
> > >I think the suggested spelling (`*`) is the confusing part. If it were
> > >to be spelled `from ` instead, it would be less confusing.
> >
> > Are you suggesting this spelling just for generator
> > comprehensions, or for list comprehensions as well?
> > What about dict comprehensions?
> For both generator, list and set comprehensions it makes sense, I think.
> For dict comprehensions: not so much. That in itself is already sign
> enough that probably the */** spelling would make more sense, while also
> allowing the `yield *foo` alternative to `yield from foo`. But what
> would be the meaning of `yield **foo`? Would that be `yield
> *foo.items()`? I have no idea.
> _______________________________________________
> Python-ideas mailing list
> Code of Conduct:
> --
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> To unsubscribe from this group and all its topics, send an email to
> For more options, visit
Python-ideas mailing list
Code of Conduct:

Reply via email to