Skip to content

Commit b7360e9

Browse files
committed
refactor and add explanatory commments & links
1 parent 33e6aa0 commit b7360e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

07-files/files7.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,28 @@
88
after_file = Path('./data/ALA_after.csv')
99
outfile = Path('./data/ALA_diff.csv')
1010

11+
# Create a set object by mapping the "before" file onto a tuple object
12+
# (an immutable list), passing teh result of `open()` to `csv.reader()`
1113
before = set(
1214
map(
1315
tuple,
1416
csv.reader(open(before_file))
1517
)
1618
)
1719

20+
# Repeat for the second ("after") file
1821
after = set(map(tuple, csv.reader(open(after_file))))
1922

23+
# Use the caret (^) operator to get the symmetric difference between the sets
24+
# https://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch16s03.html
25+
2026
differences = before ^ after
2127

2228
output = csv.writer(open(outfile, mode='w'))
2329

2430
compared = sorted(differences, key=lambda x: x[0], reverse=True)
2531

26-
for iter, row in enumerate():
32+
for count, row in enumerate():
2733
output.writerow(row)
2834

29-
print(f"Wrote {iter} rows to output file.")
35+
print(f"Wrote {count} rows to output file.")

0 commit comments

Comments
 (0)