strings.damerau_levenshtein_distance

This script is a implementation of the Damerau-Levenshtein distance algorithm.

It’s an algorithm that measures the edit distance between two string sequences

More information about this algorithm can be found in this wikipedia article: https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance

Functions

damerau_levenshtein_distance(→ int)

Implements the Damerau-Levenshtein distance algorithm that measures

Module Contents

strings.damerau_levenshtein_distance.damerau_levenshtein_distance(first_string: str, second_string: str) int

Implements the Damerau-Levenshtein distance algorithm that measures the edit distance between two strings.

Parameters:

first_string: The first string to compare second_string: The second string to compare

Returns:

distance: The edit distance between the first and second strings

>>> damerau_levenshtein_distance("cat", "cut")
1
>>> damerau_levenshtein_distance("kitten", "sitting")
3
>>> damerau_levenshtein_distance("hello", "world")
4
>>> damerau_levenshtein_distance("book", "back")
2
>>> damerau_levenshtein_distance("container", "containment")
3
>>> damerau_levenshtein_distance("container", "containment")
3