[Edu-sig] understanding recursion

Richard Holbert holbert.13 at osu.edu
Mon Feb 12 17:48:52 CET 2007


Here's another example of recursion:

def is_a_palindrome(t):
    # check to see if t is a palindrome
    if (len(t) >= 2):
        return (t[0] == t[-1]) and is_a_palindrome(t[1:-1])
    else:
        # t is either a single character, or empty string
        return True


More information about the Edu-sig mailing list