[Python-ideas] Fwd: unpacking generalisations for list comprehension
Spencer Brown
spencerb21 at live.com
Wed Oct 12 17:39:16 EDT 2016
The semantics seem fairly obvious if you treat it as changing the method calls. For lists, * uses .extend() instead of .append(). Sets use * for .update() instead of .add(). Dicts use ** for .update() instead of __setitem__. In that case x should be a mapping (or iterable of pairs maybe), and all pairs in that should be added to the dict. In generator expressions * means yield from instead of just yield. The ** in dicts is needed to distinguish between set and dict comprehensions, since it doesn't use a colon.
Spencer
On 13 Oct. 2016, at 6:41 am, אלעזר <elazarg at gmail.com<mailto:elazarg at gmail.com>> wrote:
To be honest, I don't have a clear picture of what {**x for x in d.items()} should be. But I do have such picture for
dict(**x for x in many_dictionaries)
Elazar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161012/344e5cd9/attachment.html>
More information about the Python-ideas
mailing list