sum for sequences?

Patrick Maupin pmaupin at gmail.com
Mon Mar 29 10:40:54 EDT 2010


On Mar 28, 9:45 pm, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> And what about tuples? And subclasses of list/tuples? How many different
> types need to be optimized?

One of the beautiful things about Python is that, for most things,
there are few surprises for even new users.  "There should be one
obvious way to do it" for the user means that, sometimes, under the
hood, there are a lot of special cases for the implementers.

> 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.

Right now, it's probably not, because when somebody sums a large list
and gets thwacked on the head by the lack of efficiency, they then
come here and get thwacked because "everybody knows" they should user
itertools or something else; not sum().
>
> The primary use case for sum is adding numbers when floating point
> accuracy is not critical. If you need float accuracy, use math.fsum.

See, I think the very existence of math.fsum() already violates "there
should be one obvious way to do it."

> But if anyone wants to submit a patch to the bug tracker, go right ahead.
> Without a patch though, I'd say that Python-Dev will consider this a non-
> issue.

Agreed.  Wish I had the time to do this sort of cleanup.

Regards,
Pat



More information about the Python-list mailing list