【发布时间】:2017-10-08 15:31:55
【问题描述】:
我正在尝试将文本文件拆分为句子,使用标点符号作为分隔符。到目前为止我的代码有效,但分隔符正在单独打印在一行上。如何让标点和句子保持一致?
import re
string = ""
with open("text.txt") as file:
for line in file:
for l in re.split(r"(\. |\? |\! )",line):
string += l + "\n"
print(string)
示例输出:
This is the flag of the Prooshi — ous, the Cap and Soracer
.
This is the bullet that byng the flag of the Prooshious
.
This is the ffrinch that fire on the Bull that bang the flag of the Prooshious
.
【问题讨论】:
标签: python-3.x