from difflib import Differ def diff_texts(text1, text2): d = Differ() d3= [] for token in d.compare(text1, text2): if token[0] != '-': if token[0] != " ": d3.append((token[2:], token[0])) else: d3.append((token[2:], None)) return d3