Remove line if list of bad words are found

Question:

Remove a line if an undesired word is found in the sentence. The bad words are cat and dog.
Given a text file:

orange
cat is bad
dog is bad
water
egg

I would like it to look like:

orange
water
egg

Here is my code so far. I am not sure why this still returns a text file with the sentences that include the bad words. :

bad_words=[cat, dog]
with open('some.txt','r') as f:
   lines=f.readlines()

with open('some.txt','w') as f:
for i in lines:
   if  not any(bad_word in i for bad_word in bad_words):
      f.writelines(lines)
Asked By: user18774110

||

Answers:

change f.writelines(lines) to f.writelines(i)

Answered By: Lius Morgan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.