Edit Distance in Python

Posted by Alice on Stack Overflow See other posts from Stack Overflow or by Alice
Published on 2010-03-17T06:02:07Z Indexed on 2010/03/17 6:11 UTC
Read the original article Hit count: 356

Filed under:
|
|

I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word.

I know I need to start by generating a list with an edit distance of one from the invalid word(and then run that again on all the generated words). I have three methods, inserts(...), deletions(...) and changes(...) that should output a list of words with an edit distance of 1, where inserts outputs all valid words with one more letter than the given word, deletions outputs all valid words with one less letter, and changes outputs all valid words with one different letter.

I've checked a bunch of places but I can't seem to find an algorithm that describes this process. All the ideas I've come up with involve looping through the dictionary list multiple times, which would be extremely time consuming. If anyone could offer some insight, I'd be extremely grateful. Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about edit