I have a text file structured as follows:
word 123 etc.
792 test abc
lorem ipsum word
92 testing
random 84
word 184 lmnop
Using Python, how can I delete every line that contains the word word?
# Open the input file for reading and create a new file for writing
with open("input.txt", "r") as input_file, open("output.txt", "w") as output_file:
# Iterate through each line in the input file
for line in input_file:
# Check if the line contains the word "word"
if "word" not in line:
# Write the line to the output file if it does not contain "word"
output_file.write(line)