
Feb. 12, 2015
4:06 a.m.
On 12/02/2015 4:59 p.m., Chris Angelico wrote:
Addition in the usual sense of the word wouldn't be commutative for dictionaries.
Does it have to be? It isn't commutative for strings or tuples either.
I think associativity is the property in question, and it does hold for string and tuple concatenation. Dict addition could be made associative by raising an exception on duplicate keys. Another way would be to define {'a':x} + {'a':y} as {'a': x + y}, but that would probably upset a lot of people. :-) -- Greg