[Python] python清除字符串里的非字母字符 →→→→→进入此内容的聊天室

来自 , 2020-01-22, 写在 Python, 查看 120 次.
URL http://www.code666.cn/view/e7d4c8d4
  1. s = "hello world! how are you? 0"  
  2.  
  3. # Short version  
  4. print filter(lambda c: c.isalpha(), s)  
  5.  
  6. # Faster version for long ASCII strings:  
  7. id_tab = "".join(map(chr, xrange(256)))  
  8. tostrip = "".join(c for c in id_tab if c.isalpha())  
  9. print s.translate(id_tab, tostrip)  
  10.  
  11. # Using regular expressions  
  12. print re.sub("[^A-Za-z]", "", s)  
  13. #//python/4613

回复 "python清除字符串里的非字母字符"

这儿你可以回复上面这条便签

captcha