Last active
June 23, 2019 08:42
-
-
Save joelburton/08e0fee1241e8ec0a2e9404481098690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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