Pythonic way to sum n-th list element?

Anna revanna at mn.rr.com
Mon Apr 21 23:08:58 EDT 2003


On Mon, 21 Apr 2003 16:02:27 +0000, Alex Martelli wrote:


> As a bonus -- sum([]) now returns 0, while in my original design it raised
> a ValueError, just like e.g. max([]) does.  I thought raising an error was
> best in the name of "errors shouldn't pass silently" and "in the face of
> ambiguity, refuse the temptation to guess".  But -- once we decree that
> "sum is about numbers", there's no real ambiguity, so we can have the
> little extra handiness of having sum([]) not be an error;-).

Hooray!

Sum() is a goodness! And sum([]) returns 0 is a great goodness.
Thanks Alex.

Just my $.03 worth,
Anna




More information about the Python-list mailing list