INPUT_FILENAME = 'file1'
BLACKLIST_FILENAME = 'file2'
OUTPUT_FILENAME = 'file3'
with open(BLACKLIST_FILENAME) as f:
blacklist = f.readlines()
prev_line = None
with open(OUTPUT_FILENAME, 'w') as output_file:
with open(INPUT_FILENAME) as input_file:
for line in input_file:
if line in blacklist:
prev_line = None
else:
if prev_line is not None:
output_file.write(prev_line)
prev_line = line
if prev_line is not None:
output_file.write(prev_line)