|
|
Subscribe / Log in / New account

Re: Adding "+" and "+=" operators to dict

From:  Greg <greg.ewing-F+z8Qja7x9Xokq/tPzqvJg-AT-public.gmane.org>
To:  python-ideas-+ZN9ApsXKcEdnm+yROfE0A-AT-public.gmane.org
Subject:  Re: Adding "+" and "+=" operators to dict
Date:  Thu, 12 Feb 2015 17:06:33 +1300
Message-ID:  <54DC26C9.4060801@canterbury.ac.nz>

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

_______________________________________________
Python-ideas mailing list
Python-ideas-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/




to post comments


Copyright © 2015, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds