python_reference/diff_files.py

22 lines
476 B
Python
Raw Normal View History

2014-02-10 22:39:43 +00:00
# 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:
2014-02-10 22:42:09 +00:00
id_set1.add(line.strip())
2014-02-10 22:39:43 +00:00
with open('id_file2.txt', 'r') as id_file:
for line in id_file:
2014-02-10 22:42:09 +00:00
id_set2.add(line.strip())
2014-02-10 22:39:43 +00:00
diffs = id_set2.difference(id_set1)
for d in diffs:
print(d)
print("Total differences:",len(diffs))