[Python-ideas] Adding "+" and "+=" operators to dict
Chris Angelico
rosuav at gmail.com
Thu Feb 12 04:59:28 CET 2015
On Thu, Feb 12, 2015 at 2:24 PM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
> Addition in the usual sense of the word wouldn't be commutative for
> dictionaries. In particular, it's hard to see how you could define addition
> so these two expressions are equal:
>
> {'a': 1} + {'a': 2}
>
> {'a': 2} + {'a': 1}
>
> '+=' is no problem.
Does it have to be? It isn't commutative for strings or tuples either.
Addition of complex objects does at times depend on order (though as
we saw in another thread, it can be very confusing if the _type_ can
change if you switch the operands), so I would have no problem with
the right-hand operand "winning" when there's a key collision.
ChrisA
More information about the Python-ideas
mailing list