Skip to content

Commit 71b36e6

Browse files
committed
Refactor string_utils & palidrome
1 parent ab58c26 commit 71b36e6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

palindrome/palindrome.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from string_utils import is_palindrome
1+
from . import string_utils
22

33

44
def main():
55
word = input("Type a word to test if it is palindrome: ")
6-
if is_palindrome(word):
6+
if string_utils.is_palindrome(word):
77
print(f"The word '{word}' is palindrome")
88
else:
99
print(f"The word '{word}' isn't palindrome")

palindrome/string_utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
2+
FORBIDDEN_CHARS = (".", ",", "!", ";", ":",
3+
"-", "_", "?", "/", "\\", "|", "*",
4+
"+", "=", "@", "#", "$", "%", "^",
5+
"&", "(", ")", "{", "}", "[", "]", "~", "`")
6+
17
def remove_special_char(string):
28
''' Removes all special characters from a string '''
3-
forbidden_char = (".", ",", "!", ";", ":", "-", "_", "?", "/")
49
new_string = ""
5-
for s in string:
6-
if s not in forbidden_char:
7-
new_string += s
10+
for character in string:
11+
if character not in FORBIDDEN_CHARS:
12+
new_string += character
813
return new_string
914

1015

0 commit comments

Comments
 (0)