Skip to content

Instantly share code, notes, and snippets.

@airekans
Created December 5, 2013 08:49
Show Gist options
  • Save airekans/7802133 to your computer and use it in GitHub Desktop.
Save airekans/7802133 to your computer and use it in GitHub Desktop.
Get the diff of the two sorted sequence stored in files.
import sys
if __name__ == '__main__':
file1, file2 = sys.argv[1:]
file1_fd = open(file1)
file2_fd = open(file2)
line1 = file1_fd.readline()
line2 = file2_fd.readline()
while line1 and line2:
if line1 == line2:
line1 = file1_fd.readline()
line2 = file2_fd.readline()
elif line1 < line2:
print line1.strip()
line1 = file1_fd.readline()
else:
print line2.strip()
line2 = file2_fd.readline()
while line1:
print line1.strip()
line1 = file1_fd.readline()
while line2:
print line2.strip()
line2 = file2_fd.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment