Created
September 8, 2012 09:13
-
-
Save chaomai/3672956 to your computer and use it in GitHub Desktop.
Python 3: is palindrome
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
#palindrome | |
#tested under Python3 | |
def process_text(text): | |
text = text.lower() | |
forbidden = (' ', '.', '?', '!', ':', ';', '-', '—', '(', ')', '[', ']', '’', '“', '”', '/', ',', '"') | |
for i in forbidden: | |
text = text.replace(i, '') | |
return text | |
def reverse(text): | |
return text[::-1] | |
def is_palindrome(text): | |
new = process_text(text) | |
return process_text(text) == reverse(process_text(text)) | |
something = input('Enter text: ') | |
if (is_palindrome(something)): | |
print("Yes, it is a palindrome") | |
else: | |
print("No, it is not a palindrome") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment