标签:com blog class div c code log t sp ext string
A_byte_of_Python-v192-for_Python_3.0-中文版.pdf 中的一道题:
练习题:
检测一个文本是否为回文应该忽略标点,空格和大小写。
例如”Rise to vote,
sir.”同样是一个回文,但是我们当前的例子无法识别它。你能
改善这个例子让它做都这点吗?
代码有点挫,莫笑:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 |
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" ) |
标签:com blog class div c code log t sp ext string
原文地址:http://www.cnblogs.com/xiaobaichuangtianxia/p/3701934.html