在python中,是否有使用difflib库能够得到改变的位置偏移以及改变本身的方法?
我拥有以下内容:
import difflib
text1 = 'this is a sample text'.split()
text2 = 'this is text two.'.split()
print list(difflib.ndiff(text1, text2))
这将打印:
[' this', ' is', '- a', '- sample', ' text', '+ two.']
我也能得到相应更改的偏移量吗?天真的解决方案就是搜索更改,但如果字符串随着重复术语变长,那就不起作用了。