Feature suggestion: sum() ought to use a compensated summation algorithm
Torsten Bronger
bronger at physik.rwth-aachen.de
Sat May 3 17:27:08 EDT 2008
Hallöchen!
Erik Max Francis writes:
> Szabolcs Horvát wrote:
>
>> 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.)
>
> What you wrote is nonsensical there, no different from 'a' + 1 --
> which is why it quite rightly raises a TypeError.
No, the above expression should yield ''+'abc'+'efg', look for the
signature of sum in the docs.
Tschö,
Torsten.
--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: bronger at jabber.org
(See http://ime.webhop.org for further contact info.)
More information about the Python-list
mailing list