從兩個多行字符串中獲得差異的最佳方式是什麼?Python - 獲取字符串之間的差異
a = 'testing this is working \n testing this is working 1 \n'
b = 'testing this is working \n testing this is working 1 \n testing this is working 2'
diff = difflib.ndiff(a,b)
print ''.join(diff)
這將產生:
t e s t i n g t h i s i s w o r k i n g
t e s t i n g t h i s i s w o r k i n g 1
+ + t+ e+ s+ t+ i+ n+ g+ + t+ h+ i+ s+ + i+ s+ + w+ o+ r+ k+ i+ n+ g+ + 2
什麼也正是得到的最好的方法:
testing this is working 2
?
將正則表達式在這裏的解決方案?
'b.split(a)'。? –
該死的@Chris_Rands。從來沒有想過這個!尼斯黑客。 –
@Chris_Rands很好的黑客,但這不是一個高效的方式去做 –