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

Alexander Heger python at 2sn.net
Sat Feb 14 18:59:41 CET 2015


On 14 February 2015 at 17:23, Nathan Schneider <neatnate at gmail.com> wrote:
>>  > merging two dicts certainly is _something_ like addition.
>>
>
> So is set union (merging two sets). But in Python, binary + is used mainly
> for
>
>   - numerical addition (and element-wise numerical addition, in Counter),
> and
>   - sequence concatenation.
>
> Being unordered, dicts are more like sets than sequences, so the idea of
> supporting dict1 + dict2 but not set1 + set2 makes me queasy.

But using the same operator as for sets has the same issue as updating
dicts is not the same as combining sets either.
It behaves unlike any other operation for which we use operators.  So,
we might quite well use +.


-Alexander


More information about the Python-ideas mailing list