get_close_matches() is a function that is available in the difflib Python package.
The difflib module provides classes and functions for comparing sequences. We can use this module to compare files and produce information about file differences in various formats.
We can use this function to get a list of “good matches” for a particular word.
This function accepts four parameters:
get_close_matches() function returns a list of close matched strings that satisfy the cutoff. The order of close matched string is based on similarity score, so the most similar string comes first in the list.
The code snippet below provides an example of this function.
import difflib word = "learning" possibilities = ["love", "learn", "lean", "moving", "hearing"] n = 3 cutoff = 0.7 close_matches = difflib.get_close_matches(word, possibilities, n, cutoff) print(close_matches)
get_close_matches()function and pass all the parameters defined in the above step.
Now, it is your turn to try out different parameter values in the code editor.
View all Courses