python_reference/useful_scripts/palindrome.py

15 lines
420 B
Python
Raw Normal View History

2014-04-13 19:52:40 +00:00
# Sebastian Raschka 04/2014
def palindrome(my_str):
"""
Returns True if an input string is a palindrom
"""
stripped_str = "".join([l.lower() for l in my_str if l.isalpha()])
return stripped_str == stripped_str[::-1]
if __name__ == '__main__':
test1 = 'Hello World!'
test2 = "Go hang a salami. I'm a lasagna hog."
print('test1', palindrome(test1))
print('test2', palindrome(test2))