[Python-ideas] Adding "+" and "+=" operators to dict

Rob Cliffe rob.cliffe at btinternet.com
Thu Feb 12 16:08:54 CET 2015


On 12/02/2015 14:52, Petr Viktorin wrote:
> I don't see ChainMap mentioned in this thread, so I'll fix that:
>
> On Thu, Feb 12, 2015 at 2:32 PM, Juancarlo Añez <apalala at gmail.com> wrote:
>
> [snip]
>>
>> It would also be useful if dict.update() returned self, so this would be
>> valid:
>>
>>      new_dict = {}.update(a, b, c, d)
> In today's Python:
> new_dict = dict(ChainMap(d, b, c, a))
>
> Many uses don't need the dict() call – e.g. when passing it **kwargs,
> or when it's more useful as a view.
>
> Personally, the lack of a special operator for this has never bothered me.
> _______________________________________________
>
But perhaps the fact that you have, as far as I can see, transposed b 
and c indicates that this is not the most user-friendly API. :-)
Rob Cliffe


More information about the Python-ideas mailing list