summaryrefslogtreecommitdiffstats
path: root/Doc/library/difflib.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-04-10 02:41:31 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-04-10 02:41:31 (GMT)
commit1929983518098d7bc370bd7ecb524626d6bd4a66 (patch)
tree0c89ce7f7a7f663b804501b5c2fc3eccc479570f /Doc/library/difflib.rst
parent4e6aba6f6352acd0f40a7677c678afa4079a85ba (diff)
parentdbb677a894b2d9da3945f7e3c0fdf850ea1bd3f1 (diff)
downloadcpython-1929983518098d7bc370bd7ecb524626d6bd4a66.zip
cpython-1929983518098d7bc370bd7ecb524626d6bd4a66.tar.gz
cpython-1929983518098d7bc370bd7ecb524626d6bd4a66.tar.bz2
Beautify and modernize the SequenceMatcher example
Diffstat (limited to 'Doc/library/difflib.rst')
-rw-r--r--Doc/library/difflib.rst16
1 files changed, 9 insertions, 7 deletions
diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst
index 505d308..836e240 100644
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -483,13 +483,15 @@ The :class:`SequenceMatcher` class has this constructor:
>>> b = "abycdf"
>>> s = SequenceMatcher(None, a, b)
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
- ... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
- ... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
- delete a[0:1] (q) b[0:0] ()
- equal a[1:3] (ab) b[0:2] (ab)
- replace a[3:4] (x) b[2:3] (y)
- equal a[4:6] (cd) b[3:5] (cd)
- insert a[6:6] () b[5:6] (f)
+ print('{:7} a[{}:{}] --> b[{}:{}] {!r:>8} --> {!r}'.format(
+ tag, i1, i2, j1, j2, a[i1:i2], b[j1:j2]))
+
+
+ delete a[0:1] --> b[0:0] 'q' --> ''
+ equal a[1:3] --> b[0:2] 'ab' --> 'ab'
+ replace a[3:4] --> b[2:3] 'x' --> 'y'
+ equal a[4:6] --> b[3:5] 'cd' --> 'cd'
+ insert a[6:6] --> b[5:6] '' --> 'f'
.. method:: get_grouped_opcodes(n=3)