[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/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4