我正在尝试从旧版本的文本(text1)中恢复一系列xml标记,并将它们嵌入到同一文本的最新版本(text2)中。
例如:
text1 = "this <verb>is</verb> an example of a sentence"
text2 = "this is an <noun>example</noun> of a <noun>sentence</noun>"
desired_output = "this <verb>is</verb> an <noun>example</noun> of a <noun>sentence</noun>"
目前我已经使用difflib管理两个版本,并单独使用代码:
diff = difflib.unified_diff(text1, text2, lineterm='')
print ('\n'.join(list(diff)))
给出了:
- this <verb>is</verb> an example of a sentence
+ this is an <noun>example</noun> of a <noun>sentence</noun>
我的问题是,如何将-
字符串嵌入+
字符串?