摘要: 为了对字符串中的每个字符处理可以采用下面几种方法:1. 使用内建函数list将字符串转换成列表,列表的每一项是字符串中字符1 thelist = list(TheString)2. 使用for循环直接遍历字符串中的每个字符for c in theString: do_something_with(c)3. 使用列表推倒1 result = [do_something_with(c) for c in theString]4. 使用map1 result = map(do_something_with, thesting)代码测试: 1 #!/usr/bin/env python 2 3 ... 阅读全文
posted @ 2013-01-21 16:06 uzero 阅读(162) 评论(0) 推荐(0) 编辑