Skip to content

Instantly share code, notes, and snippets.

@antonagestam
Created June 21, 2020 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonagestam/7cde8c62c294c13b611840377d42f649 to your computer and use it in GitHub Desktop.
Save antonagestam/7cde8c62c294c13b611840377d42f649 to your computer and use it in GitHub Desktop.
best matches
# from https://github.com/nemethf/mypy/blob/6e2a5ee1aedba9ec41996aa5a04ec68826a90851/mypy/messages.py#L2028
import difflib
def best_matches(current: str, options: Iterable[str]) -> List[str]:
ratios = {v: difflib.SequenceMatcher(a=current, b=v).ratio() for v in options}
return sorted((o for o in options if ratios[o] > 0.75),
reverse=True, key=lambda v: (ratios[v], v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment