Skip to content

Instantly share code, notes, and snippets.

@kylebgorman
Created June 8, 2019 19:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylebgorman/baa896af68ef508b6a73264a721d4efa to your computer and use it in GitHub Desktop.
Save kylebgorman/baa896af68ef508b6a73264a721d4efa to your computer and use it in GitHub Desktop.
Which English word is most similar to "covfefe"?
#!/usr/bin/env python
# What's the nearest word (in Levenshtein distance) to "covfefe"?
import string
# Available from: https://github.com/kylebgorman/EditTransducer
import edit_transducer
# You probably have this file if you're on Linux or Mac OS X.
with open("/usr/share/dict/words") as source:
lexicon = [line.rstrip() for line in source]
# By limiting it to ASCII letters we'll throw out "'s" words, etc.
la = edit_transducer.LevenshteinAutomaton(string.ascii_letters, lexicon)
print(la.closest_match("covfefe"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment