ID EN
Diff Tools

ndiff

Python 3.11

Compare a and b (lists of strings); return a Differ-style delta (a generator generating the delta lines).

Syntax

PYTHON
difflib.ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK)

Examples

Example 1
PYTHON
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
...              'ore\ntree\nemu\n'.splitlines(keepends=True))
>>> print(''.join(diff), end="")
- one
?  ^
+ ore
?  ^
- two
- three
?  -
+ tree
+ emu

See Also

Differ generator IS_LINE_JUNK() SequenceMatcher IS_CHARACTER_JUNK()