A_byte_of_Python-v192-for_Python_3.0-中文版.pdf 中的一道题:
练习题:
检测一个文本是否为回文应该忽略标点,空格和大小写。
例如”Rise to vote, sir.”同样是一个回文,但是我们当前的例子无法识别它。你能
改善这个例子让它做都这点吗?
代码有点挫,莫笑:
def reverse(text):
return text[::-1]
def is_huiwen(text):
return text == reverse(text)
while True:
somethine = input('Enter text:')
somethine = somethine.lower()
alist = []
for oneword in somethine:
if(oneword.isalpha()):
alist.append(oneword)
else:
continue
if (is_huiwen(alist)):
print ("YES,it's a huiwen string")
else:
print("No,it's not a huiwen string")