[Tutor] using the reduce function
Alan Gauld
alan.gauld at blueyonder.co.uk
Fri Jan 23 03:22:22 EST 2004
> Yet another homework problem is giving me fits. Here
> it goes:
Coz its homework I'll only give a clue...
> Use the reduce function to find the length of the
> longest string in a list of strings.
Reduce takes the first two elements of a list and
replaces them with the result of a function, then
repeats until the list is single valued.
So to get the longest string just compare two
strings and return the longest one. The final list
contains the longest string in the original list.
Easy... :-)
Take a look at the Functional Programming page of
my tutor for more on reduce() and its friends.
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list