[Python-Dev] Fwd: summing a bunch of numbers (or "whatevers")

Alex Martelli aleax@aleax.it
Mon, 21 Apr 2003 10:52:55 +0200

On Monday 21 April 2003 02:58 am, Guido van Rossum wrote:
> anything except sum([]) == 0, since they probably want to sum a list
> of numbers, and occasionally (albeit through a bug in their program
> :-) the list will be empty.  But that means that summing a sequence of

Errors should never pass silently, unless explicitly silenced.  I thus think
that the sum of an empty sequence should raise a ValueError (just
like the max or min of an empty sequence) and the idiom sum(L or [0])
should be taught to "sum up a list of numbers that might be empty".

> strings ends up with a strange end case.  So perhaps raising an
> exception for an empty sequence, like min() and max(), is better: "In
> the face of ambiguity, refuse the temptation to guess."  An optional


> Alex, care to send in your patch?

Aye aye, cap'n -- now that youve crossed the i's and dotted the t's
I'll arrange the complete patch with tests and docs and submit it