I'm trying to read a text from a text file, read lines, and delete short lines and lines that contain specific string (for example, 'bad' and 'naughty'). I can't seem to make this happen with this code:
bad_words = ['bad', 'naughty']
with open('oldfile.txt') as oldfile, open('newfile.txt', 'w') as newfile:
for line in oldfile:
if not any(bad_word in line for bad_word in bad_words) or len(line) > 20:
newfile.write(line)
I suspect that the problem has to do with using if and if not. Any idea how to debug this?
::there? That's going to be aSyntaxError...or/thenothere... have a think about your boolean logic :)