I have created a simple palindrome function that works only on single words. It is working as intended, but I feel that it definitely needs improvement.
def is_palindrome(w): if not isinstance(w, str): return "ERROR: input is not a string." elif len(w) > 2: if w == w[-1]: while len(w) > 2: w = w[1:-1] is_palindrome(w) if len(w) == 1: return True else: return False else: return "ERROR: input contains two or less characters." print is_palindrome('aibohphobia') print is_palindrome('definitely')
Can you please review my function and post your suggestions?
Also, is it better to do
w[:] = w[1:-1] instead of
w = w[1:-1]?