Perl の「変更」操作が何なのか、よくわかりません。PHP DIFF 出力に似ている場合は、次のコードで問題を解決します。
def sdiffer(s1, s2):
differ = difflib.Differ()
diffs = list(differ.compare(s1, s2))
i = 0
sdiffs = []
length = len(diffs)
sequence = 0
while i < length:
line = diffs[i][2:]
if diffs[i].startswith(' '):
sequence +=1
sdiffs.append((sequence,'u', line))
elif diffs[i].startswith('+ '):
sequence +=1
sdiffs.append((sequence,'+', line))
elif diffs[i].startswith('- '):
sequence +=1
sdiffs.append((sequence,'-',diffs[i][2:]))
if i+1 < length and diffs[i+1].startswith('? '):
if diffs[i+3].startswith('?') and i+3 < length : # case 2
sequence +=1
sdiffs.append((sequence,'+',diffs[i+2][2:]))
i+=3
elif diffs[i+2].startswith('?') and i+2 < length: # case 3
sequence +=1
sdiffs.append((sequence,'+',diffs[i+2][2:]))
i+=2
elif diffs[i+1].startswith('+ ') and i+2<length and diffs[i+2].startswith('? '): # case 1
sequence +=1
sdiffs.append((sequence,'+', diffs[i+1][2:]))
i += 2
else: # the line is deleted and inserted new line # case 4
sequence +=1
sdiffs.append((sequence,'+', diffs[i+1][2:]))
i+=1
i += 1
return sdiffs
コードをありがとう@Sнаđошƒаӽ。