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

Neil Girdhar mistersheik at gmail.com
Sun Feb 15 23:14:43 CET 2015


I'm also +1, I agree with Donald that "|" makes more sense to me than "+" 
if only for consistency with sets.  In mathematics a mapping is a set of 
pairs (preimage, postimage), and we are taking the union of these sets.

On Thursday, February 12, 2015 at 7:26:20 AM UTC-5, Donald Stufft wrote:
>
>
> > On Feb 12, 2015, at 5:43 AM, Steven D'Aprano <st... at pearwood.info 
> <javascript:>> wrote:
> > 
> > On Thu, Feb 12, 2015 at 01:07:52AM -0800, Ian Lee wrote:
> >> Alright, I've tried to gather up all of the feedback and organize it in
> >> something approaching the alpha draft of a PEP might look like::
> >> 
> >> 
> >> Proposed New Methods on dict
> >> ============================
> >> 
> >> Adds two dicts together, returning a new object with the type of the 
> left
> >> hand operand. This would be roughly equivalent to calling:
> >> 
> >>>>> new_dict = old_dict.copy();
> >>>>> new_dict.update(other_dict)
> > 
> > A very strong -1 on the proposal. We already have a perfectly good way 
> > to spell dict += , namely dict.update. As for dict + on its own, we have 
> > a way to spell that too: exactly as you write above.
> > 
> > I think this is a feature that is more useful in theory than in 
> > practice. Which we already have a way to do a merge in place, and a 
> > copy-and-merge seems like it should be useful but I'm struggling to 
> > think of any use-cases for it. I've never needed this, and I've never 
> > seen anyone ask how to do this on the tutor or python-list mailing 
> > lists.
>
> I’ve wanted this several times, explicitly the copying variant of it. I 
> always
> get slightly annoyed whenever I have to manually spell out the copy and the
> update.
>
> I still think it should use | rather than + though, to match sets.
>
> ---
> Donald Stufft
> PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
>
> _______________________________________________
> Python-ideas mailing list
> Python... at python.org <javascript:>
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150215/5341646a/attachment.html>


More information about the Python-ideas mailing list