<p style="margin-top: 0px; margin-bottom: 0px;"><pre name="code" class="python">#quote from MIT 'introduction to computation and programming using python, Revised'
def isPalindrome(s):
"""Assumes s is a str
Returns True if the letters in s form a palindrome;
False otherwise. Non-letters and capitalization are ignored."""
def toChars(s):
s = s.lower()
letters = ''
for c in s:
if c in 'abcdefghijklmnopqrstuvwxyz':
letters += c
return letters
def isPal(s):
if len(s) <= 1:
return True
else:
return s[0] == s[-1] and isPalindrome(s[1:-1])
return isPal(toChars(s))
isPalindrome('xyyx')
Out[14]: True
isPalindrome('hello')
Out[15]: False