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

Donald Stufft donald at stufft.io
Thu Feb 12 20:10:40 CET 2015


> On Feb 12, 2015, at 1:42 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> 
> Which is another way of saying that there is no one obviously correct
> and generally useful way to merge two dicts. Well, actually there is
> one, and we already have the dict.update method to do it. If +
> duplicates that, it's redundant, and if it doesn't, it's non-obvious
> and likely to be of more limited use.

The fact that we already have dict.update indicates to me that the way
dict.update works is the sensible way for + and += to work. I mean by your
logic why do we have + and += for lists? People could just use copy() and
extend() if they wanted to.

Wanting to add two dictionaries is a fairly common desire, both with and
without copying. If it weren't then it wouldn't pop up with some regularity
on python-ideas. The real questionis what semantics do you give it, which I
think is a fairly silly question because we already have the semantics defined
via dict.update() and the dictionary literal and the dict() constructor itself.

---
Donald Stufft
PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150212/ff64c7d3/attachment.sig>


More information about the Python-ideas mailing list