Skip to content

Instantly share code, notes, and snippets.

Last active Jul 16, 2021
What would you like to do?
Python / Language / Palindrome -
# Write a function called is_palindrom
# You can use built-in funciton len to check the string length
# A palindorm is a word that is spelled the same backward and forward
# Example: noon, redivider
def first(word): return word[0]
def last(word): return word[-1]
def middle(word): return word[1:-1]
def is_palindrome(word):
if (first(word) != last(word)):
return False
if (len(word) > 2):
return is_palindrome(middle(word))
return True
print(is_palindrome("noon")) # True
print(is_palindrome("redivider")) # True
print(is_palindrome("to")) # False
print(is_palindrome("moomm")) # False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment