What\'s the best way of getting just the difference from two multiline strings?
a = \'testing this is working \\n testing this is working 1 \\n\'
b = \'testi
You could use the following function:
def __slave(a, b):
for i, l_a in enumerate(a):
if b == l_a:
return i
return -1
def diff(a, b):
t_b = b
c_i = 0
for c in a:
t_i = __slave(t_b, c)
if t_i != -1 and (t_i > c_i or t_i == c_i):
c_i = t_i
t_b = t_b[:c_i] + t_b[c_i+1:]
t_a = a
c_i = 0
for c in b:
t_i = __slave(t_a, c)
if t_i != -1 and (t_i > c_i or t_i == c_i):
c_i = t_i
t_a = t_a[:c_i] + t_a[c_i+1:]
return t_b + t_a
Usage sample print diff(a, b)