Use SequenceMatcher to return list of the best "good enough" matches.
word is a sequence for which close matches are desired (typically a
string).
possibilities is a list of sequences against which to match word
(typically a list of strings).
Optional arg n (default 3) is the maximum number of close matches to
return. n must be > 0.
Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities
that don't score at least that similar to word are ignored.
The best (no more than n) matches among the possibilities are returned
in a list, sorted by similarity score, most similar first.
>>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
['apple', 'ape']
>>> import keyword as _keyword
>>> get_close_matches("wheel", _keyword.kwlist)
['while']
>>> get_close_matches("apple", _keyword.kwlist)
[]
>>> get_close_matches("accept", _keyword.kwlist)
['except']
Definition at line 571 of file difflib.py.
573 """Use SequenceMatcher to return list of the best "good enough" matches.
575 word is a sequence for which close matches are desired (typically a
578 possibilities is a list of sequences against which to match word
579 (typically a list of strings).
581 Optional arg n (default 3) is the maximum number of close matches to
582 return. n must be > 0.
584 Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities
585 that don't score at least that similar to word are ignored.
587 The best (no more than n) matches among the possibilities are returned
588 in a list, sorted by similarity score, most similar first.
590 >>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
592 >>> import keyword as _keyword
593 >>> get_close_matches("wheel", _keyword.kwlist)
595 >>> get_close_matches("apple", _keyword.kwlist)
597 >>> get_close_matches("accept", _keyword.kwlist)
602 raise ValueError(
"n must be > 0: " + `n`)
603 if not 0.0 <= cutoff <= 1.0:
604 raise ValueError(
"cutoff must be in [0.0, 1.0]: " + `cutoff`)
608 for x
in possibilities:
610 if s.real_quick_ratio() >= cutoff
and \
611 s.quick_ratio() >= cutoff
and \
613 result.append((s.ratio(), x))
621 return [x
for score, x
in result]