45 lines
697 B
Python
45 lines
697 B
Python
import difflib
|
|
|
|
s1 = "1234asdffooMOO"
|
|
s2 = "asdfbarMOOwhatever"
|
|
|
|
# s1 = "asdffoo"
|
|
# s2 = "asdffooMOO"
|
|
|
|
def onestepchange(start, dest):
|
|
|
|
ret = ""
|
|
|
|
for i, s in enumerate(difflib.ndiff(start, dest)):
|
|
# print(i)
|
|
# print(s)
|
|
|
|
if s[0] == '-':
|
|
return ret + start[i+1:]
|
|
|
|
if s[1] == '+':
|
|
return ret + s[-1] + start[i:]
|
|
|
|
ret = ret + s[-1]
|
|
|
|
if len(ret) > len(start):
|
|
return ret
|
|
|
|
if ret[i] != start[i]:
|
|
return ret + start[i:]
|
|
|
|
return ret
|
|
|
|
|
|
n = s1
|
|
while n != s2:
|
|
print(n)
|
|
n = onestepchange(n, s2)
|
|
|
|
print(n)
|
|
|
|
# for i, s in enumerate(difflib.ndiff(s1, s2)):
|
|
# print(i)
|
|
# print(s)
|
|
|