import difflib
text1_lines = "I understand how customers do their choice. Difference"
text2_lines = "I understand how customers do their choice."
diff = difflib.ndiff(text1_lines, text2_lines)
if len(a) == 0:
print b
return
if len(b) == 0:
print a
return
if len(a)>len(b):
res=''.join(a.split(b)) #get diff
else:
res=''.join(b.split(a)) #get diff
print(res.strip())
import difflib
import sys
text1_lines = "I understand how customers do their choice. Difference"
text2_lines = "I understand how customers do their choice."
diff = difflib.context_diff(text1_lines, text2_lines)
for line in diff:
sys.stdout.write(line)
使用简单的列表理解:
它会给你看删节和附录
输出:
^{pr2}$(后面带负号的所有内容都被删除)
相反,切换
text1_lines
和text2_lines
会产生这样的结果:要删除标志,可以转换以上列表:
要完全转换为字符串,只需使用
.join()
:把大的绳子和小的绳子分开,你就会得到不同的结果。在
从Docs:
输出:
^{pr2}$相关问题 更多 >
编程相关推荐