私はメソッドを持つ以下のクラスを持っている:私はそれを達成したいことは['regards', 'Regards']
切断は
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)
01:私はこのような出力を探しています
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(9月、1)[0]' 'lineNew + = sep' – Vinay