1

我正在尝试从旧版本的文本(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>

我的问题是,如何将-字符串嵌入到+字符串中?

4

0 回答 0