diff --git a/difftest.py b/difftest.py new file mode 100644 index 0000000..ad84eb3 --- /dev/null +++ b/difftest.py @@ -0,0 +1,44 @@ +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) +