[Python-checkins] cpython (merge 3.2 -> default): Beautify and modernize the SequenceMatcher example

raymond.hettinger python-checkins at python.org
Sun Apr 10 04:41:48 CEST 2011


http://hg.python.org/cpython/rev/aff9bcbd2fc7
changeset:   69230:aff9bcbd2fc7
parent:      69227:b7456c1b4aa4
parent:      69229:35f4e0d1d64b
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Apr 09 19:41:31 2011 -0700
summary:
  Beautify and modernize the SequenceMatcher example

files:
  Doc/library/difflib.rst |  16 +++++++++-------
  1 files changed, 9 insertions(+), 7 deletions(-)


diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -483,13 +483,15 @@
         >>> 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)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list