all Python 3difflibfunction
difflib.restore()
diff formats
Rebuilds one of the original sequences from the output of ndiff() or Differ.compare(): which=1 or 2.
Syntax
difflib.restore(sequence, which)
It only works with the ndiff format: unified_diff() and context_diff() output will not do, since they omit equal lines outside the context and use other prefixes. which accepts only 1 or 2, otherwise ValueError. So an ndiff result can be stored instead of both versions of the text.
Examples
import difflib
delta = list(difflib.ndiff(['a\n', 'b\n'], ['a\n', 'c\n']))
print(''.join(difflib.restore(delta, 1)).split()) # → ['a', 'b']
print(''.join(difflib.restore(delta, 2)).split()) # → ['a', 'c']
See also
Open in the full glossarydocs.python.orgReport an inaccuracy