From b6939de24738ecfbb9f09ae872f37e24b1cfec44 Mon Sep 17 00:00:00 2001 From: grizax Date: Wed, 14 Jan 2015 10:50:32 -0500 Subject: [PATCH 1/3] up --- palindrome.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 palindrome.py diff --git a/palindrome.py b/palindrome.py new file mode 100644 index 0000000..148c171 --- /dev/null +++ b/palindrome.py @@ -0,0 +1,36 @@ +''' +Still needs closure, output, and prints. Needs To Use "is a palindrome" and "is not a palindrome" at closure + +Could use the following for normalize: + +def remove(s): + sentence = re.sub(r'[^A-Za-z]', '',sentence) + return sentence +''' + + + +sentence = input("Please enter your sentence or sentences: ") + +print("Removing characters. Lowering cases...") + +def overseer(s): + + def normalizing(s): + """converting characters to ascii and alphanumeric letters""" + return u"".join(i if isPlainASCIIAlphaNum(i) else '' for i in s) + #could use re.sub here + + def lowering_case(s): + return s.lower() + + def palindrome(s): + if len(s) <= 1: + return True + else: + boolean = s[0] == s[-1] and palindrome(s[1:-1]) + return(boolean) + + return palindrome(normalize(s)) + +return sentence From adabd147a7985e3593c5169224bad63b4506ca44 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 8 Apr 2015 16:12:49 -0400 Subject: [PATCH 2/3] refactored palindrome app --- palindrome.py | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/palindrome.py b/palindrome.py index 148c171..94bee6a 100644 --- a/palindrome.py +++ b/palindrome.py @@ -1,36 +1,24 @@ -''' -Still needs closure, output, and prints. Needs To Use "is a palindrome" and "is not a palindrome" at closure +import re -Could use the following for normalize: +def normalizing(user_string): + """Removes all nonalpha characters and converts all letters to lowercase""" + search_string = re.compile("[^A-Za-z]") + return re.sub(search_string, '', user_string).lower() -def remove(s): - sentence = re.sub(r'[^A-Za-z]', '',sentence) - return sentence -''' +def palindrome(s): + """Function that determines if the string is a palindrome""" + if len(s) <= 1: + return True + else: + boolean = s[0] == s[-1] and palindrome(s[1:-1]) + return(boolean) sentence = input("Please enter your sentence or sentences: ") -print("Removing characters. Lowering cases...") -def overseer(s): - - def normalizing(s): - """converting characters to ascii and alphanumeric letters""" - return u"".join(i if isPlainASCIIAlphaNum(i) else '' for i in s) - #could use re.sub here - - def lowering_case(s): - return s.lower() - - def palindrome(s): - if len(s) <= 1: - return True - else: - boolean = s[0] == s[-1] and palindrome(s[1:-1]) - return(boolean) - - return palindrome(normalize(s)) - -return sentence +if palindrome(normalizing(sentence)): + print("That is a palindrome") +else: + print("That is not a palindrome") From 027449e63015f8b271a40cafb5a0e230d0c837cb Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 8 Apr 2015 16:14:20 -0400 Subject: [PATCH 3/3] pass pep8 and pyflakes tests --- palindrome.py | 1 + 1 file changed, 1 insertion(+) diff --git a/palindrome.py b/palindrome.py index 94bee6a..66f69dc 100644 --- a/palindrome.py +++ b/palindrome.py @@ -1,5 +1,6 @@ import re + def normalizing(user_string): """Removes all nonalpha characters and converts all letters to lowercase""" search_string = re.compile("[^A-Za-z]")