如何获得列表中的差异

时间:2017-04-15 06:24:20

标签: python list join tuples difflib

以下是两个元组列表:

text1_lines = [('a','1'), ('b', '2'), ('c','3')]
text2_lines = [('a','4'), ('z', '5'), ('c','6')]

我可以通过以下代码获得差异

d = difflib.Differ()
diff = d.compare(text1_lines,text2_lines)
diff_list = '\n'.join(diff)

请建议如何将diff_list转换为列表,以便我可以遍历列表。

1 个答案:

答案 0 :(得分:0)

知道了。

d = difflib.Differ()
diff = d.compare(text1_lines,text2_lines)
diff =  list(diff)
for item in diff:
    print(item)