[Python-ideas] Fast sum() for non-numbers
Ron Adam
ron3200 at gmail.com
Wed Jul 10 23:00:31 CEST 2013
On 07/10/2013 12:49 PM, Steven D'Aprano wrote:
> On 11/07/13 02:10, Sergey wrote:
>> On Jul 9, 2013 Steven D'Aprano wrote:
>>
>>> The fact that sum(lists) has had quadratic performance since sum
>>> was first introduced in Python 2.3, and I've *never* seen anyone
>>> complain about it being slow, suggests very strongly that this is not
>>> a use-case that matters.
>>
>> Never seen? Are you sure? ;)
>>> http://article.gmane.org/gmane.comp.python.general/658630
>>> From: Steven D'Aprano @ 2010-03-29
>>> In practical terms, does anyone actually ever use sum on more than a
>>> handful of lists? I don't believe this is more than a hypothetical
>>> problem.
>
> Yes, and I stand by what I wrote back then.
Just curious, how does your sum compare with fsum() in the math module?
(Yes, I know it's specialised for floats?) It says that much in the docs.
fsum(...)
fsum(iterable)
Return an accurate floating point sum of values in the iterable.
Assumes IEEE-754 floating point arithmetic.
Have you looked at it?
Cheers,
Ron
More information about the Python-ideas
mailing list