Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1929983

Browse files
committed
Beautify and modernize the SequenceMatcher example
2 parents 4e6aba6 + dbb677a commit 1929983

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

Doc/library/difflib.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,15 @@ The :class:`SequenceMatcher` class has this constructor:
483483
>>> b = "abycdf"
484484
>>> s = SequenceMatcher(None, a, b)
485485
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
486-
... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
487-
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
488-
delete a[0:1] (q) b[0:0] ()
489-
equal a[1:3] (ab) b[0:2] (ab)
490-
replace a[3:4] (x) b[2:3] (y)
491-
equal a[4:6] (cd) b[3:5] (cd)
492-
insert a[6:6] () b[5:6] (f)
486+
print('{:7} a[{}:{}] --> b[{}:{}] {!r:>8} --> {!r}'.format(
487+
tag, i1, i2, j1, j2, a[i1:i2], b[j1:j2]))
488+
489+
490+
delete a[0:1] --> b[0:0] 'q' --> ''
491+
equal a[1:3] --> b[0:2] 'ab' --> 'ab'
492+
replace a[3:4] --> b[2:3] 'x' --> 'y'
493+
equal a[4:6] --> b[3:5] 'cd' --> 'cd'
494+
insert a[6:6] --> b[5:6] '' --> 'f'
493495

494496

495497
.. method:: get_grouped_opcodes(n=3)

0 commit comments

Comments
 (0)