On this page
  1. difflib.SequenceMatcher
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

difflib.SequenceMatcher

Prev: difflib.restore | Up: difflib | Next: difflib.unified_diff
Rel: difflib.context_diff, difflib.diff_bytes, difflib.Differ, difflib.get_close_matches
Ref: docs.python.org — difflib.SequenceMatcher
Tags: #public #python3 #stdlib #difflib


Import

import difflib
from difflib import SequenceMatcher

Signature & Overview

difflib.SequenceMatcher(isjunk=None, a='', b='', autojunk=True)

SequenceMatcher is a flexible class for comparing pairs of sequences of any type, so long as the sequence elements are hashable. The basic algorithm predates, and is a little fancier than, an algorithm

Methods & Attributes

Usage

import difflib

sm = difflib.SequenceMatcher(None, "kitten", "sitting")
assert 0.5 < sm.ratio() < 0.7
assert any(tag == "replace" for tag, *_ in sm.get_opcodes())

Gotchas

REPL Inspect

from difflib import SequenceMatcher
help(SequenceMatcher)

Linked from

Related notes