max(), sum(), next()
tino at wildenhain.de
Thu Sep 11 10:51:11 CEST 2008
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
More information about the Python-list