我想用python重新拆分()将一个句子用逗号分隔成多个字符串,但我不希望应用于用逗号分隔的单个单词,例如:
示例
s = "Yes, alcohol can have a place in a healthy diet."
desired result = ["Yes, alcohol can have a place in a healthy diet."]
另一个例子:
s = "But, of course, excess alcohol is terribly harmful to health in a variety of ways, and even moderatealcohol intake is associated with an increase in the number two cause of premature death: cancer."
desired output = ["But, of course" , "excess alcohol is terribly harmful to health in a variety of ways" , "and even moderatealcohol intake is associated with an increase in the number two cause of premature death: cancer."]
有什么建议吗?拜托。你知道吗
由于Python不支持regex中的可变长度lookbehind assertions,因此我将使用
re.findall()
:说明:
相关问题 更多 >
编程相关推荐