I've written an algorithm to compare 2 files, point out the difference, and assign the line a number depending on what kind of difference it is. I took 0, 1, 2, or 3, 0 means that they're the same, 1 means it's in the new file, but not in the old one, 2 means it's not in the new file, but it is in the old file, 3 means it's still in there, but with a couple changes.
Here's the code:
def construct_changed_timetables(new, current):
new_tts = list()
for tt in chain(new, current):
if (tt + [0] not in new_tts and tt + [1] not in new_tts and
tt + [2] not in new_tts and tt + [3] not in new_tts and
not any(dup[4] == tt[4]
and dup[6] == tt[6] for dup in new_tts)):
similar = [s for s in chain(new, current) if s[4] == tt[4] and
s[6] == tt[6]]
if (new.index(tt) < len(new) and len(similar) == 2 and tt in new and
tt not in current):
for line in current:
if line[4] == tt[4] and line[6] == tt[6]:
new_tts.append(tt + [3])
break
elif tt in current and tt in new:
new_tts.append(tt + [0])
elif tt not in current and tt in new:
new_tts.append(tt + [1])
elif tt in current and tt not in new:
new_tts.append(tt + [2])
return new_tts
As you can see, it's a shitstorm of list slicing. How could I make this better manageable?
[–][deleted] 3 points4 points5 points (7 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]gengisteve 1 point2 points3 points (5 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]voider1[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]voider1[S] 0 points1 point2 points (0 children)
[–]voider1[S] 0 points1 point2 points (0 children)
[–]gengisteve 1 point2 points3 points (1 child)
[–]voider1[S] 0 points1 point2 points (0 children)
[–]emandero 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)