The get_close_matches() function of difflib module in Pyhon

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:

# 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:

List of words:
['fun', 'run', 'funny', 'fumes', 'funnel']
Close matches:
['fun', 'funny', 'run']

 


Copyright 2026 © pythontic.com