mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-23 20:11:13 +00:00
palindrome
This commit is contained in:
parent
a05c40a854
commit
47e4aca99c
14
useful_scripts/palindrome.py
Normal file
14
useful_scripts/palindrome.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# 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))
|
Loading…
Reference in New Issue
Block a user