max(), sum(), next()
bborcic at gmail.com
Sat Sep 13 12:00:42 CEST 2008
Tino Wildenhain wrote:
> Luis Zarrabeitia wrote:
>> Quoting Laszlo Nagy <gandalf at shopzeus.com>:
>> Even better:
>> help(sum) shows
>> sum(sequence, start=0) -> value
>> Returns the sum of a sequence of numbers (NOT strings) plus
>> the value
>> of parameter 'start'. When the sequence is empty, returns start.
>> so the fact that sum() returns zero is just because the start value
>> is zero...
>> sum(,object()) would return an object().
>> BTW, the original code:
>>>>> sum(s for s in ["a", "b"] if len(s) > 2)
>> wouldn't work anyway... it seems that sum doesn't like to sum strings:
>> <type 'exceptions.TypeError'>: sum() can't sum strings [use
>> ''.join(seq) instead]
> Yes which is a bit bad anyway. I don't think hard wiring it is such a
> nice idea. You know, walks like a duck, smells like a duck...
> If it makes sense to handle things differently for performance, then
> please have it doing it silently, e.g. when it detects strings just
> use join() internally.
''.join is horrible. And it adds insult to injury that S.join(S.split(T)) != T
as a rule. The interpreter has no business to patronize us into this shamefully
contorted neighborhood while it understands what we want.
More information about the Python-list