Pythonic way to sum n-th list element?
Alex Martelli
aleax at aleax.it
Sun Apr 20 03:47:39 EDT 2003
Steven Taschuk wrote:
> Quoth Alex Martelli:
> [...]
>> So, I tried implementing sum in the simplest way, as a
>> separate patch to operator.c (leaving add alone) -- THAT
>> gives me 124 microseconds, a 50% speedup with respect to
>> the simple for loop and clearly sufficient to justify
>> sum's existence (together with its simplicity, clarity,
>> and likely frequency of use). [...]
>
> +1. Optimization of the most common case. Excellent.
>
> I'm not sure such a sum function belongs in the operator module,
> though. At the moment I think it might fit best as a built-in; it
> goes nicely with min and max.
Yes, this seems to be the general feeling of those who have
responded on python-dev so far, with, however, one important
exception -- Raymond Hettinger thinks there are already too
many built-ins, so he'd rather add a new module instead.
Alex
More information about the Python-list
mailing list