def describe_diff(a, b):
    a = a.splitlines()
    b = b.splitlines()

    for tag, i1, i2, j1, j2 in SequenceMatcher(None, a, b).get_opcodes():
        if tag == 'equal':
            for idx, line in enumerate(b[j1:j2]):
                yield (idx + j1 + 1, ' ', _make_unicode(line))
            continue
        if tag == 'replace' or tag == 'delete':
            for idx, line in enumerate(a[i1:i2]):
                yield (idx + i1 + 1, '-', _make_unicode(line))
        if tag == 'replace' or tag == 'insert':
            for idx, line in enumerate(b[j1:j2]):
                yield (idx + j1 + 1, '+', _make_unicode(line))
Takes two strings and calculates the difference between them.
dataset/ETHPy150Open robmadole/jig/src/jig/diffconvert.py/describe_diff