I\'m trying to read a text from a text file, read lines, delete lines that contain specific string (in this case \'bad\' and \'naughty\').
The code I wrote goes like this:>
bad_words = ['doc:', 'strickland:','\n']
with open('linetest.txt') as oldfile, open('linetestnew.txt', 'w') as newfile:
for line in oldfile:
if not any(bad_word in line for bad_word in bad_words):
newfile.write(line)
The \n is a Unicode escape sequence for a newline.