作为脚本的一部分,我有:
User
.find()
.batchSize(999999)
.limit(105)
.exec();
有没有办法用一条线完成所有这些?
答案 0 :(得分:2)
正常表达救援!
import re
text = re.sub(r'[?,. ]', '- ', text)
答案 1 :(得分:0)
我确信有更多的Pythonic方式,但是:
text = text.replace('?',' ').replace(',',' ').replace('.',' ').replace(' ','- ')
答案 2 :(得分:0)
这可能也不是Pythonic,但无需导入re
模块即可运行:
text = "".join((i if i not in '?,.' else '- ' for i in text))