forked from IvarsKarpics/git_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.py
More file actions
25 lines (21 loc) · 719 Bytes
/
palindrome.py
File metadata and controls
25 lines (21 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import copy
import string
def is_palindrome(word):
# Make check for palindrome independent of whitespace, punctuation
# and capitalisation. It has not been specified if digits should
# be ignored or not, so they are left in.
chars = list(word.translate(None, string.punctuation + string.whitespace).lower())
rev = copy.copy(chars)
rev.reverse()
if rev == chars:
return True
else:
return False
def test():
print("Is word a palindrome?")
print("radar?", is_palindrome("radar"))
print("brexit?", is_palindrome("brexit"))
print("Able was I ere I saw Elba?",
is_palindrome("Able was I ere I saw Elba"))
if __name__ == '__main__':
test()