25 lines
622 B
Python
25 lines
622 B
Python
|
def isPalindrome(s: str) -> bool:
|
||
|
tmp = s
|
||
|
tmp = tmp.lower()
|
||
|
def is_char(ch):
|
||
|
if (ch >= 'a' and ch <= 'z') or (ch >= '0' and ch <= '9'):
|
||
|
return True
|
||
|
return False
|
||
|
exp = []
|
||
|
for lt in tmp:
|
||
|
if is_char(lt):
|
||
|
exp.append(lt)
|
||
|
length = len(exp)
|
||
|
for index, ele in enumerate(exp):
|
||
|
if(exp[index] != exp[length - index - 1]):
|
||
|
return False
|
||
|
return True
|
||
|
|
||
|
s = 'A man, a plan a canal: Panama'
|
||
|
print(isPalindrome(s))
|
||
|
s = " "
|
||
|
print(isPalindrome(s))
|
||
|
s = "race a car"
|
||
|
print(isPalindrome(s))
|
||
|
s = "0P"
|
||
|
print(isPalindrome(s))
|