Feature suggestion: sum() ought to use a compensated summation algorithm

Arnaud Delobelle arnodel at googlemail.com
Sat May 3 16:38:21 EDT 2008


Szabolcs Horvát <szhorvat at gmail.com> writes:

> Arnaud Delobelle wrote:
>>
>> sum() works for any sequence of objects with an __add__ method, not
>> just floats!  Your algorithm is specific to floats.
>
> This occurred to me also, but then I tried
>
> sum(['abc', 'efg'], '')
>
> and it did not work.  Or is this just a special exception to prevent
> the misuse of sum to join strings?  (As I said, I'm only an occasional
> user.)

I think that's right: anything with an __add__ method, apart from
string, can be sum()ed.

-- 
Arnaud



More information about the Python-list mailing list