I presently have code that deletes all lines from a text file that contain one specific string. Here it is:
import os
with open(r"oldfile") as f, open(r"workfile", "w") as working:
for line in f:
if "string1" not in line:
working.write(line)
os.remove(r"oldfile")
os.rename(r"workfile", r"oldfile")
My question is: how can I include other strings? In other words, I want to tell the script that if a line contains "string1" or some other string "string2", then delete that line. I know I could just repeat the code I put above for every such string, but I'm certain there's some shorter and more efficient way to write that.
Many thanks in advance!