how to delete a specific line in a file

searched = "snow" # every line containing the variable "searched" will be deleted

with open("file.txt","r+") as f: # open your file
    new_f = f.readlines()
    f.seek(0)
    for line in new_f:
        if searched not in line:
            f.write(line)
    f.truncate() # close your file

Here is what the above code is Doing:
1. Open the file in read and write mode
2. Read all the lines in the file and store them in a list
3. Go back to the beginning of the file
4. Iterate through the list of lines
5. If the line does not contain the word “snow”, write it to the file
6. Truncate the file to remove the lines that were not written