0

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.

  • Writing a list to a file with Python, with newlines. https://stackoverflow.com/questions/899103/writing-a-list-to-a-file-with-python-with-newlines – Сергей Кох Oct 29 '22 at 08:42

0 Answers0