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

Joshua Landau joshua at landau.ws
Tue Jul 16 00:40:01 CEST 2013


On 15 July 2013 23:27, Ron Adam <ron3200 at gmail.com> wrote:
> So ...
>
>      + 1   Add specialised sum_iters(),  (based on the sum() patch.)

You mean chain.from_iterable? That's the fastest we're getting for
iterables. Maybe sum_lists() could be faster, but then we're into "if
you need that niche and you need it that fast, write it yourself"
territory.

>      + .5  increase other options speed.. (not easy or even possible)
>      + .25  Patch sum, and document it's use for sequences. [1]
>
> [1] Assuming this can be done with no backwards compatibility or new side
> effects.  Lots of new tests should be added for this.

But then it doesn't duck-type well ⇒ people should avoid using it ⇒
the original change just becomes an attractive nuisance

chain.from_iterable doesn't have this problem.

> By far, the easiest and least problematic choice is to add a new function.


More information about the Python-ideas mailing list