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

C Anthony Risinger anthony at xtfx.me
Tue Feb 17 23:38:14 CET 2015


On Tue, Feb 17, 2015 at 4:22 PM, C Anthony Risinger <anthony at xtfx.me> wrote:
>
>
> All of the operations support arbitrary iterables as the RHS! This is NICE.
>
> ASIDE: `d1 | d2` is NOT the same as .update() here (though maybe it should
> be)... I believe this stems from the fact that (IIRC :) a normal set() WILL
> NOT replace an entry it already has with a new one, if they hash() the
> same. IOW, a set will prefer the old object to the new one, and since the
> values are tied to the keys, the old value persists.
>
> Something to think about.
>

Forgot to mention the impl supports arbitrary iterables as the LHS as well,
with values simply becoming None. Whether RHS or LHS, a type(fancy_dict) is
always returned.

I really really want to reiterate the fact that values are IGNORED... if
you just treat a dict like a set with values hanging off the key, the
implementation stays perfectly consistent with sets, and does the same
thing no matter what it's operating with.  Just pretend like the values
aren't there and what you get in the end makes a lot of sense.

-- 

C Anthony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150217/cc9a04c7/attachment.html>


More information about the Python-ideas mailing list