我修补了一个列表,使其看起来像另一个:
a = [x for x in "qabxcd"]
b = [x for x in "abycdf"]
c = a[:]
s = SequenceMatcher(None, a, b)
for tag, i1, i2, j1, j2 in s.get_opcodes():
print ("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
(tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))
if tag == "delete":
del c[i1:i2]
elif tag == "replace":
c[i1:i2] = b[j1-1:j2-1]
elif tag == "insert":
c[i1:i2] = b[j1:j2]
print c
print b
print c == b
a == b
但列表不相等:
delete a[0:1] (['q']) b[0:0] ([])
equal a[1:3] (['a', 'b']) b[0:2] (['a', 'b'])
replace a[3:4] (['x']) b[2:3] (['y'])
equal a[4:6] (['c', 'd']) b[3:5] (['c', 'd'])
insert a[6:6] ([]) b[5:6] (['f'])
['a', 'b', 'x', 'b', 'd', 'f']
['a', 'b', 'y', 'c', 'd', 'f']
False
问题是什么?