What tool or algorithm should I use to generate words from a keyword which is at a given DamerauâLevenshtein distance?
<p>Damerau-Levenshtein distance is like:</p>

<pre><code>"abcd", "aacd" =&gt; 1 DL distance
"abcd", "aadc" =&gt; 2 DL distance
</code></pre>

<ul>
<li>More about editdistance: <a href="https://pypi.python.org/pypi/editdistance" rel="nofollow">https://pypi.python.org/pypi/editdistance</a></li>
<li>More about Damerau-Levenshtein distance:
<a href="https://pypi.python.org/pypi/pyxDamerauLevenshtein" rel="nofollow">https://pypi.python.org/pypi/pyxDamerauLevenshtein</a></li>
</ul>

<p>I can use pyxDamerauLevenshtein modul in python to determine the DL distance of 2 words. I would like to make a generator method which can produce every words of a given keyword parameter in a given DL distance.
I deal with 1 or 2 DL distances only.</p>

<p>Are any tool in python which can I use to generate words of a word in a given DL distance?</p>

<p>Look at this Norvig's article: <a href="http://norvig.com/spell-correct.html" rel="nofollow">How to Write a Spelling Corrector</a>.</p>

<p>It contains the exact code that you need:</p>

<pre><code>def edits1(word):
    "All edits that are one edit away from `word`."
    letters    = 'abcdefghijklmnopqrstuvwxyz'
    splits     = [(word[:i], word[i:])    for i in range(len(word) + 1)]
    deletes    = [L + R[1:]               for L, R in splits if R]
    transposes = [L + R[1] + R[0] + R[2:] for L, R in splits if len(R)&gt;1]
    replaces   = [L + c + R[1:]           for L, R in splits if R for c in letters]
    inserts    = [L + c + R               for L, R in splits for c in letters]
    return set(deletes + transposes + replaces + inserts)

def edits2(word): 
    "All edits that are two edits away from `word`."
    return (e2 for e1 in edits1(word) for e2 in edits1(e1))
</code></pre>

python edit-distance