
Feb. 12, 2015
3:59 a.m.
On Thu, Feb 12, 2015 at 2:24 PM, Skip Montanaro <skip.montanaro@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