0

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?

0

1 Answer 1

1
# 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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.