sum for sequences?

Patrick Maupin pmaupin at
Sun Mar 28 18:46:07 CEST 2010

On Mar 28, 10:17 am, Duncan Booth < at invalid.invalid>
> Doing add-in-place isn't the only way to make sum more efficient: if you
> assume that addition is associative (which of course the builtin sum can't)
> then you can form partial sums. e.g. instead of calculating:
> Doing it this way helps summing lists or strings (though not as much as
> str.join), but it also helps if you need to sum a long list of similarly
> sized floats as you'll get a more accurate answer.

Also, partial sums would be a clear winner over add-in-place if
someone were dumb^H^H^H^Hnaive enough to use sum() on a long list of
tuples :-)

More information about the Python-list mailing list