mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 22:11:13 +00:00
22 lines
476 B
Python
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))
|