如何打印出两个文本之间的差异(Python)

时间:2015-11-02 12:39:44

标签: python difference

我的代码是这样的:

text1 = "I like apple"
text2 = "I like car"
if text1 != text2:
   print "the differences are:"the_difference

输出应为:

the differences are:car


感谢阅读

1 个答案:

答案 0 :(得分:0)

text1 = "I like apple"
text2 = "I like car"
set1 = set(text1.split())
set2 = set(text2.split())
diffs = set1.symmetric_difference(set2)