How can I remove the multiple returns from my code without ruining the output or having errors?
My code has multiple returns and I want it to have a single return but whenever I try to change it into one return it ruins my code and it doesn't escalate the way I want it.
My Code:
def is_palindrome(s):
"""
-------------------------------------------------------
Recursively determines if s is a palindrome. Ignores non-letters and case.
Use: palindrome = is_palindrome(s)
-------------------------------------------------------
Parameters:
s - a string (str)
Returns:
palindrome - True if s is a palindrome, False otherwise (boolean)
-------------------------------------------------------
"""
if len(s) <= 1:
return True
else:
if not s[0].isalpha():
return is_palindrome(s[1:])
elif not s[-1].isalpha():
return is_palindrome(s[:-1])
if s[0].lower() != s[len(s) - 1].lower():
return False
else:
return is_palindrome(s[1:-1])