[Python-ideas] Allow using ** twice

Haoyi Li haoyi.sg at gmail.com
Thu Jun 6 17:17:36 CEST 2013


> I read `dict1 | dict2` as a mapping that would try dict1 *or* dict2 if
the key is not in dict1.

Idea:

dict1 + dict2 -> dict2 takes priority
dict1 | dict2 -> dict1 takes priority

Does that make sense to anyone? Both + and | are currently un-used iirc.


On Thu, Jun 6, 2013 at 11:11 AM, Oscar Benjamin
<oscar.j.benjamin at gmail.com>wrote:

> On 6 June 2013 16:08, Zachary Ware <zachary.ware+pyideas at gmail.com> wrote:
> >> However you can make a class that will try several mappings
> sequentially e.g.:
> >
> > That sounds rather like collections.ChainMap.
>
> So it does. Thanks for pointing this out; I wasn't aware of it. So as
> of PYthon 3.3 you can do:
>
> from collections import ChainMap
>
> func(**ChainMap(dict1, dict2))
>
> Although this does not have the behaviour suggested by the OP (an
> error when a key is duplicated).
>
>
> Oscar
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130606/ce67f30a/attachment.html>


More information about the Python-ideas mailing list