如何使用python对给定字符串进行句子简化

时间:2016-10-26 05:26:57

标签: python-3.x

  

示例:我要去金奈,我会去办公室。

     答:发送1:我要去钦奈。

    Sent 2 : I will go to office.

2 个答案:

答案 0 :(得分:0)

对于给定的示例,它可能适用于str.split: https://www.tutorialspoint.com/python/string_split.htm 如果您有更复杂的东西要分割,请尝试使用正则表达式: https://docs.python.org/3/library/re.html

答案 1 :(得分:0)

my_sent = "I am going to Chennai, then i will go to office."
sent1 , sent2 = my_sent.split(", than")

方法 split 按给定的字符或字符串值拆分字符串,并返回由给定字符分隔的元素列表。 现在我们可以将这些值放入变量中。在该示例中, sent1 sent2