Photo by Jon Tyson / Unsplash

TIL - Python's difflib.get_close_matches Gives You Built-in "Did You Mean?" Logic

Today I Learned Jun 6, 2026

You don't need a third-party library to implement fuzzy matching for typos. The difflib module does this out of the box using the Ratcliff/Obershelp algorithm.

from difflib import get_close_matches

words = ["apple", "banana", "apricot", "application"]

# Find the closest matches, max 2 results, with a minimum similarity threshold
matches = get_close_matches("appel", words, n=2, cutoff=0.6)

print(matches)  # ['apple']

This is excellent for CLI applications when a user mistypes a command or a configuration key.

Tags