python_reference/howtos_as_py_files/diff_files.py
2014-04-29 22:28:50 -04:00

22 lines
476 B
Python

# Sebastian Raschka, 2014
#
# Print lines that are different between 2 files. Insensitive
# to the order of the file contents.
id_set1 = set()
id_set2 = set()
with open('id_file1.txt', 'r') as id_file:
for line in id_file:
id_set1.add(line.strip())
with open('id_file2.txt', 'r') as id_file:
for line in id_file:
id_set2.add(line.strip())
diffs = id_set2.difference(id_set1)
for d in diffs:
print(d)
print("Total differences:",len(diffs))