As the name suggests this tool returns a list of closed
matched strings that satisfy the cutoff. The get_close_matches() method takes in four parameters of
which for finding the matches of which two are optional. Following are the
parameters that it accepts.
Thus the Syntax of get_close_matches() is:
get_close_matches(word,possibilities,n,cutoff)
Lets take an Example
CODE
import difflib
from difflib import get_close_matches
possibilities=['pythonsecrets', 'cpp', 'c', 'python','linux']
match = get_close_matches('cppsecrets',possibilities,n=4,cutoff=0.2)
print("Best matches:", match)
OUTPUT
In the above code possibilities is the pattern of of strings that is go
be matched with the word that is the input string "cppsecrets".The cutoff parameter is taken as 0.2 whereas the maximum number of close matches to be returned is taken as n=4.
Thus the close matches are returned in "Best matches" list.
Comments