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

Chris Rebert pyideas at rebertia.com
Tue Mar 17 19:14:51 CET 2009


On Tue, Mar 17, 2009 at 10:58 AM, Ka-Ping Yee <python at zesty.ca> wrote:
> 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.

Not to put words into people's mouths, but it seems like the concern
was really less over the non-commutativity and move over the fact that
data from the first dict gets silently clobbered by the second dict;
whereas in the list, tuple, and string cases, no data is ever lost in
the process.

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-ideas mailing list