Skip to content

Instantly share code, notes, and snippets.

@joelburton
Last active June 23, 2019 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelburton/08e0fee1241e8ec0a2e9404481098690 to your computer and use it in GitHub Desktop.
Save joelburton/08e0fee1241e8ec0a2e9404481098690 to your computer and use it in GitHub Desktop.
def is_palindrome(word, i=0):
"""Is word a palindrome?
>>> is_palindrome("noon")
True
>>> is_palindrome("tacocat")
True
>>> is_palindrome("zacbz")
False
"""
# winning base case: reach middle of word
if i >= len(word) // 2:
return True
if word[i] != word[-i-1]:
return False
return is_palindrome(word, i + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment