[Tutor] using the reduce function
Christopher Spears
cspears2002 at yahoo.com
Thu Jan 22 18:31:56 EST 2004
Yet another homework problem is giving me fits. Here
it goes:
Use the reduce function to find the length of the
longest string in a list of strings.
I have been banging my head against the wall with this
one. Ouch! I figured out how to do it another way
using control structures:
>>> strings = ['long', 'longer', 'longest']
>>> for i in range(len(strings)):
count = 0
if len(strings[i]) > count:
count = len(strings[i])
>>> count
7
So how do I use the logic of this script and apply it
to the problem?
-Chris
=====
"I'm the last person to pretend that I'm a radio. I'd rather go out and be a color television set."
-David Bowie
"Who dares wins"
-British military motto
"Far more creativity, today, goes into the marketing of products than into the products themselves..."
-"Pattern Recognition" by William Gibson
More information about the Tutor
mailing list