Skip to main content

spec.similar

spec.similar(word, candidates)

The one candidate that is close to word, or None.

The match is difflib.get_close_matches with a cutoff of 0.75; word itself is never its own suggestion, and the candidates are sorted first so that the result does not depend on their order.

Parameters

Name Type Description Default
word str The name that matched nothing. required
candidates Iterable[str] The valid names. required

Returns

Name Type Description
str | None str | None: The best match, or None when nothing is close enough.

Examples

from babregen.spec import similar

print(similar("pase", ["pace", "public", "summary"]))
print(similar("risk", ["pace", "public", "summary"]))
pace
None