我有以下類方法:切割句子的
class Trigger():
def getRidOfTrashPerSentence(self, line, stopwords):
countWord = 0
words = line.split()
for word in words:
if countWord == 0:
if word in stopwords:
sep = word
lineNew = line.split(sep, 1)[0]
countWord = countWord + 1
return(lineNew)
stopwords = ['regards', 'Regards']
def getRidOfTrash(self, aTranscript):
result = [self.getRidOfTrashPerSentence(line, self.stopwords) for line in aTranscript]
return(result)
我想實現它在句子切「垃圾」的某些觸發字後像['regards', 'Regards']
所以,當我想插入這樣一個塊:
aTranScript = [ "That's fine, regards Henk", "Allright great"]
我在尋找這樣的輸出:
aTranScript = [ "That's fine, regards", "Allright great"]
然而,當我這樣做:
newFile = Trigger()
newContent = newFile.getRidOfTrash(aTranScript)
我只得到"That's fine"
。
我如何能得到的任何想法都串
你如何在拆分後附加分隔符? 這裏是一個類似的問題 - http://stackoverflow.com/questions/7866128/python-split-without-removing-the-delimiter – Vinay
我不明白你什麼你Vinay,你能詳細說明一下嗎? –
你可以做到這一點 - 'lineNew = line.split(SEP,1)[0]' 'lineNew + = sep' – Vinay