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

Florian Bruhin me at the-compiler.org
Thu Feb 12 09:59:40 CET 2015


* M.-A. Lemburg <mal at egenix.com> [2015-02-12 09:51:22 +0100]:
> However, I don't really see the point in having an operation that
> takes two dictionaries, creates a new empty one and updates this
> with both sides of the operand. It may be theoretically useful,
> but it results in the same poor performance you have in string
> concatenation.
> 
> In applications, you normally just need the update functionality
> for dictionaries. If you do need a copy, you can create a copy
> explicitly - but those cases are usually rare.
> 
> So +1 on the '+=' syntax, -1 on '+' for dicts.

I think it'd be rather confusing if += works but + does not.

Regarding duplicate keys, IMHO only two options make sense:

1) Raise an exception
2) The right-hand side overrides keys in the left-hand side.

I think #1 would prevent many useful cases where + could be used
instead of .update(), so +1 for #2.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150212/9e04afd6/attachment.sig>


More information about the Python-ideas mailing list