[Guido van Rossum] > > > > - the identity (defaulting to 0) if the sequence is empty > > - the first and only element if the sequence only has one element > > - (...(((A + B) + C) + D) + ...) if the sequence has more than one element
[Greg Ewing] > While this might be reasonable if the identity > argument is not specified, I think that if an > identity is specified, it should be used even > if the sequence is non-empty. The reason being > that the user might be relying on that to get > the semantics he wants. > > Think of the second argument as "accumulator > object" rather than "identity". But I think the logical consequence of your approach would be that sum([]) should raise an exception rather than return 0, which would be backwards incompatible. Because if the identity element has a default value, the default value should be used exactly as if it were specified explicitly. Unfortunately my proposal is also backwards incompatible, since currently sum([1,1], 40) equals 42. I guess nobody remembers why we did it the way it is? -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com