9952 explained code solutions for 126 technologies

pythonRemove duplicate lines from text file

We'll remove duplicate lines from input.txt and write result to output.txt

lines_seen = set()
with open('output.txt', 'w') as output_file:
	for each_line in open('input.txt', 'r'):
	    if each_line not in lines_seen:
	        lines_seen.add(each_line)ctrl + c

declare set to store unique lines

with open

opens specified file for reads

if each_line not in lines_seen

check if this line is duplicate


write unique line to output.txt


save unique line to seen lines