I have been trying to extract all the sentences in my text file with a keyword and I was able to do it with the below code:
sentences = nltk.sent_tokenize(allwords)
for s in sentences: print(s)
for s in sentences:
if "police" in s:
print(s)
allwords is my text file and I have extracted all the sentences with the word "police" in them. Now I want to save all the sentences with the keyword in to new text file. how do I do that? I am new to Python and any help would be appreciated.