rgb192
asked on
understand how s and s11 shorten one character and then grow one character at a time because there is no loop.
def toChars(s):
import string
#s = string.lower(s)
s = s.lower()
ans = ''
for c in s:
#if c in string.lowercase:
if c in s:
ans = ans + c
return ans
def isPal(s):
if len(s) <= 1:
return True
else:
s11=s[1:-1]
equation=(s[0] == s[-1])
returnequation=equation
returnispal=isPal(s[1:-1])
returnboth=returnequation and returnispal
return returnboth
def isPalindrome(s):
"""Returns True if s is a palindrome and False otherwise"""
mychars=toChars(s)
returnispal=isPal(mychars)
return returnispal
print (isPalindrome('Guttag'))
print (isPalindrome('Guttug'))
print (isPalindrome('Able was I ere I saw Elba'))
print (isPalindrome('Are we not drawn onward, we few, drawn onward to new era?'))
I created variables so I can see changes in a debugger ide
in def is Palindrome(s)
I do not understand how s and s11 shorten one character and then grow one character at a time because there is no loop.
the ispal function is being called recursively.
ASKER
line
19
26
or both
and how
19
26
or both
and how
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks