Skip to content

difflib.SequenceMatcher.get_opcodes #140761

@DomoticaVirginia

Description

@DomoticaVirginia

Bug report

Bug description:

from difflib import SequenceMatcher
a = "qabxwzcd"
b = "abycdf"
s = SequenceMatcher(None, a, b)
for tag, i1, i2, j1, j2 in s.get_opcodes():
    print('{:7}   a[{}:{}] --> b[{}:{}] {!r:>8} --> {!r}'.format(tag, i1, i2, j1, j2, a[i1:i2], b[j1:j2]))

This is the output:

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]     'wz' --> 'cd'
insert    a[6:6] --> b[5:6]       '' --> 'f'

In the penultimate line - the one with the equal tag - it is 'wz' --> 'cd'?

Thank you very much

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions