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

Nikolaus Rath Nikolaus at rath.org
Sat Feb 14 00:22:00 CET 2015


Alexander Heger <python-ePO413wvQzY at public.gmane.org> writes:
>> As far as I was, and still am, concerned, & is the obvious and most
>> natural operator for concatenation. [1, 2]+[3, 4] should return [4, 6],
>> and sum(bunch of lists) should be a meaningless operation, like
>> sum(bunch of HTTP servers). Or sum(bunch of dicts).
>
> This only works if the items *can* be added.  Dics should not make
> such an assumption. & is not a more natural operator, because, why
> would you then not just expect that [1, 2] & [3, 4] returns [1 & 2, 3
> & 4] == [0 , 0] ?  the same would be true for any operator you pick.

Which brings us back to the idea to introduce elementwise variants of
any operator:

[1,2] .+ [3,4] == [1+3, 2+4]
[1,2] + [3,4] == [1,2,3,4]
[1,2] .& [3,4] == [1 & 3, 2 & 4]
[1,2] & [3,4] == not (yet?) defined

As a regular numpy user, I'd be very happy about that too :-).


Best,
-Nikolaus

-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«


More information about the Python-ideas mailing list