max(), sum(), next()
mensanator at aol.com
Wed Sep 10 19:48:17 CEST 2008
On Sep 7, 3:38 pm, Luis Zarrabeitia <ky... at uh.cu> wrote:
> Quoting Mensanator <mensana... at aol.com>:
> > Actualy, I already get the behaviour I want. sum([1,None])
> > throws an exception. I don't see why sum() doesn't throw
> > an exception also
> If you take a "start value" and add to it every element of a list, should the
> process fail if the list is empty?
> If you don't add anything to the start value,
> you should get back the start value.
> Python's sum is defined as sum(sequence, start=0).
That's the issue.
> If sum were to throw an
> exception with sum(), it should also throw it with sum(, start=0), wich
> makes no sense.
Given that definition, yes. But is the definition correct
in ALL cases? Are there situations where the sum of an empty
list should NOT be 0? Of course there are.
Can sum() handle those cases? No, it can't, I have to write
my own definition if I want that behaviour. There's no reason
why sum() and sum(,0) have to mean the same thing at the
exclusion of a perfectly valid alternative definition.
But that's the way it is, so I have to live with it.
But that's not conceeding that I'm wrong.
> Luis Zarrabeitia
> Facultad de Matemática y Computación, UHhttp://profesores.matcom.uh.cu/~kyrie
More information about the Python-list