<h2 id="code-snippets">Code snippets</h2>
<p>Install the Levenshtein package.</p>
<pre class="bash"><code>&gt;&gt;&gt; pip install levenshtein</code></pre>
<p>Use the Levenshtein package to calculate the edit distance.</p>
<pre class="python"><code>&gt;&gt;&gt; import Levenshtein
&gt;&gt;&gt; Levenshtein.distance(&quot;cat&quot;, &quot;dog&quot;)
3
&gt;&gt;&gt; Levenshtein.distance(&quot;cat&quot;, &quot;can&quot;)
1</code></pre>
<p>Install the TheFuzz package.</p>
<pre class="bash"><code>&gt;&gt;&gt; pip install thefuzz</code></pre>
<p>Use TheFuzz to calculate the similarity ratio.</p>
<pre class="python"><code>&gt;&gt;&gt; from thefuzz import fuzz
&gt;&gt;&gt; fuzz.ratio(&quot;cat&quot;, &quot;dog&quot;)
0
&gt;&gt;&gt; fuzz.ratio(&quot;cat&quot;, &quot;can&quot;)
67</code></pre>
<p>Use TheFuzz to calculate the similarity ratio for each item in a
list.</p>
<pre class="python"><code>&gt;&gt;&gt; from thefuzz import process
&gt;&gt;&gt; options = [&quot;dog&quot;, &quot;can&quot;]
&gt;&gt;&gt; process.extract(&quot;cat&quot;, options, limit=2)
[(&#39;can&#39;, 67), (&#39;dog&#39;, 0)]
&gt;&gt;&gt; process.extract(&quot;cat&quot;, options, limit=1)
[(&#39;can&#39;, 67)]
&gt;&gt;&gt; process.extract(&quot;cat&quot;, options, limit=2, scorer=fuzz.ratio)
[(&#39;can&#39;, 67), (&#39;dog&#39;, 0)]</code></pre>
<h2 id="other-resources">Other resources</h2>
<ul>
<li>Ethan Nam's <a
href="https://medium.com/@ethannam/understanding-the-levenshtein-distance-equation-for-beginners-c4285a5604f0">Understanding
the Levenshtein Distance Equation for Beginners</a></li>
<li><a href="https://pypi.org/project/thefuzz/">Levenstein
package</a></li>
<li><a href="https://pypi.org/project/thefuzz/">TheFuzz</a></li>
</ul>
