2009/12/5 Georg Brandl email@example.com:
Vitor Bosshard schrieb:
2009/12/5 George Sakkis firstname.lastname@example.org:
On Sat, Dec 5, 2009 at 6:45 PM, Andre Engels email@example.com wrote:
On Sat, Dec 5, 2009 at 12:55 PM, Ram Rachum firstname.lastname@example.org wrote:
I noticed that `sum` tries to add zero to your iterable. Why? Why not just skip adding any start value if none is specified?
This current behavior is preventing me from using `sum` to add up a bunch of non- number objects.
In your proposed implementation, sum() would be undefined.
Which would make it consistent with min/max.
And in that case the special string handling could also be dropped?
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> sum(["a","b"], "start") TypeError: sum() can't sum strings [use ''.join(seq) instead]
This behaviour is quite bothersome. Sum can handle arbitrary objects in theory (as long as they define the correct special methods, etc.), but it gratuitously raises an exception on strings.
This seems to be an instance where the "practicality" Zen rule beats the "special cases" rule :)
It might be more accurate to say "hand-holding" instead of practicality (and it doesn't even catch all errors it's meant to). I'm not so sure that's special enough ;-)