2017-04-15 81 views
0

下面的差異元組的兩個列表:如何獲取列表

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成列表,以便我可以遍歷列表。

+0

...刪除'join'? – melpomene

回答

0

明白了。

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