Think Python: How to Think Like a Computer Scientist

(singke) #1
                while   i<j:
if word[i] != word[j]:
return False
i = i+1
j = j-1
return True

Or we could reduce to a previously solved problem and write:


def is_palindrome(word):
return is_reverse(word, word)

Using is_reverse from Figure 8-2.

Free download pdf