1
1
def is_palindrome (s : str ) -> bool :
2
2
"""
3
- Determine whether the string is palindrome
4
- :param s:
5
- :return: Boolean
6
- >>> is_palindrome("a man a plan a canal panama".replace(" ", ""))
3
+ Determine if the string s is a palindrome.
4
+
5
+ >>> is_palindrome("A man, A plan, A canal -- Panama!")
7
6
True
8
7
>>> is_palindrome("Hello")
9
8
False
@@ -14,15 +13,15 @@ def is_palindrome(s: str) -> bool:
14
13
>>> is_palindrome("Mr. Owl ate my metal worm?")
15
14
True
16
15
"""
17
- # Since Punctuation , capitalization, and spaces are usually ignored while checking
18
- # Palindrome, we first remove them from our string.
19
- s = "" .join ([ character for character in s .lower () if character .isalnum ()] )
16
+ # Since punctuation , capitalization, and spaces are often ignored while checking
17
+ # palindromes, we first remove them from our string.
18
+ s = "" .join (character for character in s .lower () if character .isalnum ())
20
19
return s == s [::- 1 ]
21
20
22
21
23
22
if __name__ == "__main__" :
24
- s = input ("Enter string to determine whether its palindrome or not : " ). strip ( )
23
+ s = input ("Please enter a string to see if it is a palindrome : " )
25
24
if is_palindrome (s ):
26
- print ("Given string is palindrome" )
25
+ print (f"' { s } ' is a palindrome. " )
27
26
else :
28
- print ("Given string is not palindrome" )
27
+ print (f"' { s } ' is not a palindrome. " )
0 commit comments