[Tutor] using the reduce function
Karl Pflästerer
sigurd at 12move.de
Thu Jan 22 19:57:33 EST 2004
On 23 Jan 2004, Karl Pflästerer <- sigurd at 12move.de wrote:
[Code]
here is another solution; it's a bit nearer to the imperative one. It
uses reduce with a default value (it wil also be a bit faster than the
first one).
def longer2 (ln, seq):
lns = len(seq)
if ln > lns: return ln
else: return lns
def longest2 (seq):
return reduce(longer2, seq, 0)
I think there is no further explaination necessary.
Karl
--
Please do *not* send copies of replies to me.
I read the list
More information about the Tutor
mailing list