Code snippets
Install the Levenshtein package.
>>> pip install levenshteinUse the Levenshtein package to calculate the edit distance.
>>> import Levenshtein
>>> Levenshtein.distance("cat", "dog")
3
>>> Levenshtein.distance("cat", "can")
1Install the TheFuzz package.
>>> pip install thefuzzUse TheFuzz to calculate the similarity ratio.
>>> from thefuzz import fuzz
>>> fuzz.ratio("cat", "dog")
0
>>> fuzz.ratio("cat", "can")
67Use TheFuzz to calculate the similarity ratio for each item in a
list.
>>> from thefuzz import process
>>> options = ["dog", "can"]
>>> process.extract("cat", options, limit=2)
[('can', 67), ('dog', 0)]
>>> process.extract("cat", options, limit=1)
[('can', 67)]
>>> process.extract("cat", options, limit=2, scorer=fuzz.ratio)
[('can', 67), ('dog', 0)]
SOCIAL SHARE CARD GENERATOR