diff = difflib.ndiff(foo, bar)
diff = list(diff)
print(''.join(difflib.restore(diff, 2)))
''.join(difflib.restore(diff, 2)) == ''.join(bar)
How to apply the output of python's difflib.unified_diff to the original string?