The get_close_matches() function of difflib module in Pyhon

From a list of given words, the function get_close_matches() of the Python difflib module finds a list of close matches for a given word.

Difflib Module Updated 26 Mar 2026 1 min read

Function Signature

get_close_matches(word, possibilities, n, cutoff)

Parameters

word – a Python string for which close matches to be found

possibilities - A sequence containing Python strings from which close matches to be found

n – Number of close matches to be found

cutoff - The similarity score using which the close matches to be determined

Overview

For a given word, the function get_close_matches() returns a specified number of close matches from a sequence of strings. e.g., From a list of strings.

Example

python
# Example Python program that finds close matches

            # for a given word from a list words using

            # the difflib Python standard library module

            import difflib

# List of words

            words = ["fun", "run", "funny", "fumes", "funnel"]

# Word to be found for close matches

            wordToFind     = "fun"

# Get close matches

            closeMatches = difflib.get_close_matches(wordToFind, words)

            print("List of words:")

            print(words)

print("Close matches:")

            print(closeMatches)

Output

Output
List of words:

            ['fun', 'run', 'funny', 'fumes', 'funnel']

            Close matches:

            ['fun', 'funny', 'run']