>>> import re
>>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest')
['foot', 'fell', 'fastest']
>>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat')
'cat in the hat'
只需简单的操作时,字符串方法最好用,因为它们易读,又容易调试: >>> 'tea for too'.replace('too', 'two')
'tea for two'
|
Archiver|手机版|笨鸟自学网 ( 粤ICP备20019910号 )
GMT+8, 2025-8-30 08:40 , Processed in 0.015748 second(s), 20 queries .
Powered by Discuz! X3.5
© 2001-2017 Discuz Team. Template By 【未来科技】【 www.wekei.cn 】