sentence = "Very disorganized and hard professor. Does not come to classes on time, she grades tough, does not help on anything. She says come for help but when you go to her office hour, she is not there to help."
我想把这个句子分成句号、逗号和&;的几个部分;但是。 输出应该是
Very disorganized
and hard professor.
Does not come to classes on time,
she grades tough,
does not help on anything.
She says come for help
but when you go to her office hour,
she is not there to help.
现在我用的是
sample = re.split(r' *[\.\?!][\'"\)\]]* *', sentence)
print (sample)
这只会打断句号。 输出
['Very disorganized and hard professor', 'Does not come to classes on time, she grades tough, does not help on anything', 'She says come for help but when you go to her office hour, she is not there to help']
你知道怎么做吗
或者一个循环
在每个分隔符后添加
\n
输出:
可以使用^{} 在遇到停止字的地方添加换行符
正则表达式很简单:
(and|\.|but|,)
,它与你的stopwords匹配。然后将该组替换为自身,再加上一个换行符如果要将其列在列表中:
如果要删除以下每行前面的空白,可以使用以下方法:
试试这个
相关问题 更多 >
编程相关推荐