this is the search for the nearest neighbor in a metric space with levenshtein distance as a function of metric (or distance)
a VP-tree is one way to solve this problem
this Python VP-tree implementation is a working demo showing how the VP-tree tree works, say, in the list of words that it provides an interactive shell in which you enter a word and returns words in this list that are no more than distance X from the word you entered
source share