Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to compare two text files in python

with open('some_file_1.txt', 'r') as file1:
    with open('some_file_2.txt', 'r') as file2:
        same = set(file1).intersection(file2)

same.discard('
')

with open('some_output_file.txt', 'w') as file_out:
    for line in same:
        file_out.write(line)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #compare #text #files #python
ADD COMMENT
Topic
Name
6+1 =