[Python-ideas] PEP: Dict addition and subtraction

Antoine Pitrou solipsis at pitrou.net
Fri Mar 15 07:25:22 EDT 2019


On Mon, 4 Mar 2019 15:57:38 -0800
Guido van Rossum <guido at python.org> wrote:
> 
> > Those two points make me uncomfortable with "+=" strictly behaving
> > like ".update()".
> 
> And yet that's how it works for lists. (Note that dict.update() still has
> capabilities beyond +=, since you can also invoke it with keyword args.)

Yeah, well.... I do think "+=" for lists was a mistake.  I *still* have
trouble remembering the exact difference between "list +=" and
"list.extend" (yes, there is one: one accepts more types than the
other... which one it is, and why, I never remember; and, of course,
there might be the obscure performance difference because of
CPython's execution details).

I should not have to remember whether I want to use "list +=" or
"list.extend" every time I need to extend a list.  There is a virtue to

"""There should be one-- and preferably only one --obvious way to do
it"""

and we shouldn't break it more than we already did.

Regards

Antoine.




More information about the Python-ideas mailing list