[Python-ideas] dict '+' operator and slicing support for pop

Ka-Ping Yee python at zesty.ca
Tue Mar 17 18:58:47 CET 2009


On Tue, 17 Mar 2009, Josiah Carlson wrote:

> On Tue, Mar 17, 2009 at 9:03 AM, George Sakkis <george.sakkis at gmail.com> wrote:
>> On Tue, Mar 17, 2009 at 11:00 AM, Andrii V. Mishkovskyi
>> <mishok13 at gmail.com> wrote:
>>
>>> 1. Add ability to use '+' operator for dicts
>>>
>
> Both of the ideas suffer from "+ is no longer commutative", which
> sort-of bothers me.

I don't find that a convincing argument, since + is not commutative
for lists or tuples either.  Andrii's original proposal is the most
natural interpretation -- notice that if x and y are dicts:

     dict(x.items()) gives x

     dict(x.items() + y.items()) gives x + y

That looks perfectly consistent to me.

George's counter-proposal doesn't make sense to me at all -- it
messes up the types of all the values in the dict.  And it's
inconsistent with the built-in behaviour of + with other types:
it doesn't add lists element-by-element, so it shouldn't add
dicts element-by-element either.


-- ?!ng



More information about the Python-ideas mailing list