difflib.get_close_matches
Prev: difflib.Differ | Up: difflib | Next: difflib.HtmlDiff
Rel: difflib.context_diff, difflib.diff_bytes, difflib.Differ, difflib.HtmlDiff
Ref: docs.python.org — difflib.get_close_matches
Tags: #public #python3 #stdlib #difflib
Import
import difflib
from difflib import get_close_matches
Signature & Overview
difflib.get_close_matches(word, possibilities, n=3, cutoff=0.6)
Use SequenceMatcher to return list of the best "good enough" matches.
Usage
import difflib
matches = difflib.get_close_matches("appel", ["ape", "apple", "peach", "puppy"], n=2, cutoff=0.6)
assert matches[0] == "apple"
Gotchas
- Great for CLI "Did you mean...?" suggestions: Tune
cutoff(default0.6, range0..1) to control fuzziness.
REPL Inspect
from difflib import get_close_matches
help(get_close_matches)
Linked from
- tuts/python3/stdlib_module/difflib
- tuts/python3/stdlib_module/difflib/context_diff
- tuts/python3/stdlib_module/difflib/diff_bytes
- tuts/python3/stdlib_module/difflib/Differ
- tuts/python3/stdlib_module/difflib/HtmlDiff
- tuts/python3/stdlib_module/difflib/Match
- tuts/python3/stdlib_module/difflib/ndiff
- tuts/python3/stdlib_module/difflib/restore
- tuts/python3/stdlib_module/difflib/SequenceMatcher
- tuts/python3/stdlib_module/difflib/unified_diff
Related notes
- tuts/python3/stdlib_module/difflib/context_diff Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/diff_bytes Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/Differ Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/HtmlDiff Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/difflib/Match links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/ndiff links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/restore links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/SequenceMatcher links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/unified_diff links to this page; shared tags: #difflib, #stdlib