[Python-ideas] adding dictionaries
Alexander Heger
python at 2sn.net
Tue Jul 29 00:20:53 CEST 2014
> https://mail.python.org/pipermail/python-ideas/2013-June/021140.html.
I see, this is a very extended thread google did not show me when I
started this one, and many good points were made there.
So, my apologies I restarted this w/o reference; this discussion does
seem to resurface, however.
It seems it would be valuable to parallel the behaviour of operators
already in place for collections. Counter:
A + B adds values (calls __add__ or __iadd__ function of values,
likely __iadd__ for values of A)
A |= B does A.update(B)
etc.
-Alexander
On 29 July 2014 05:21, Paul Moore <p.f.moore at gmail.com> wrote:
> On 28 July 2014 19:58, Nathan Schneider <nathan at cmu.edu> wrote:
>> Here are two threads that had some discussion of this:
>> https://mail.python.org/pipermail/python-ideas/2011-December/013227.html
>
> This doesn't seem to have a use case, other than "it would be nice".
>
>> https://mail.python.org/pipermail/python-ideas/2013-June/021140.html.
>
> This can be handled using ChainMap, if I understand the proposal.
>
>> Seems like a useful feature if there could be a clean way to spell it.
>
> I've yet to see any real-world situation when I've wanted "dictionary
> addition" (with any of the various semantics proposed here) and I've
> never encountered a situation where using d1.update(d2) was
> sufficiently awkward that having an operator seemed reasonable.
>
> In all honesty, I'd suggest that code which looks bad enough to
> warrant even considering this feature is probably badly in need of
> refactoring, at which point the problem will likely go away.
>
> Paul
More information about the Python-ideas
mailing list