Jul-17-2018, 10:05 AM
You have to use
And then use a for loop to iterate over each line of contents.
At the end I put an
readlines()
to get a list of each line in the file.And then use a for loop to iterate over each line of contents.
At the end I put an
elif
to get "results" too, to match the expected outputs.with open('file1.txt', "r") as f1: contents = f1.readlines() with open('output1.txt', "w+") as f2: for line in contents: if "comb" not in line: if "input" in line: f2.write(line) elif "output" in line: f2.write(line) elif "assign" in line: f2.write(line) elif "result" in line: f2.write(line)