[Python-ideas] Fast sum() for non-numbers

Steven D'Aprano steve at pearwood.info
Fri Jul 12 02:23:47 CEST 2013


On 11/07/13 23:20, Ron Adam wrote:
> How do you feel about adding the ability of sum to sum vectors or lists of values to each other?
>
> sum([[x1, y1], [x2, y2], ...])  --->  [x1+x2, y1+y2]

What I think of that is that it is not backward compatible and would completely break any code relying on sum's current behaviour.

We're in the middle of a long discussion arguing that a *tiny*, *subtle* shift in behaviour of sum is sufficient to disqualify the change, and you're suggesting something that completely changes the semantics from list concatenation to element-by-element addition. No offence Ron, but have you been reading the rest of the thread?

If anyone wants element-by-element addition, then can either define a class that does so using the + operator (say, numpy arrays) or they define their own function.

Or try to revive PEP 225:

http://www.python.org/dev/peps/pep-0225/


-- 
Steven


More information about the Python-ideas mailing list