Skip to content

Instantly share code, notes, and snippets.

@naiaden
Created March 21, 2018 14:31
Show Gist options
  • Select an option

  • Save naiaden/3bd3420586eb22d103a7779602391e7b to your computer and use it in GitHub Desktop.

Select an option

Save naiaden/3bd3420586eb22d103a7779602391e7b to your computer and use it in GitHub Desktop.
Returns the differences between strings
import difflib
import sys
if len(sys.argv) < 3:
print("Usage: %s string1 string2" % sys.argv[0])
sys.exit()
a = sys.argv[1]
b = sys.argv[2]
s = difflib.SequenceMatcher(None, a, b)
for tag, i1, i2, j1, j2 in s.get_opcodes():
print ("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
(tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment