From 47e4aca99ceba0d469efc78fffdc073c2f2a962c Mon Sep 17 00:00:00 2001 From: rasbt Date: Sun, 13 Apr 2014 15:52:40 -0400 Subject: [PATCH] palindrome --- useful_scripts/palindrome.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 useful_scripts/palindrome.py diff --git a/useful_scripts/palindrome.py b/useful_scripts/palindrome.py new file mode 100644 index 0000000..003139e --- /dev/null +++ b/useful_scripts/palindrome.py @@ -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))