Levenshtein¶
- levenshtein(s1: str, s2: str) int¶
Calculate the Levenshtein distance between two strings.
- Parameters:
s1 (str) – The first string.
s2 (str) – The second string.
- Returns:
The Levenshtein distance between
s1ands2.- Return type:
int
- Raises:
TypeError – If
s1ors2are not strings.
Example Usage:
from mandelshtam import levenshtein s1 = "mandelshtam" s2 = "levenshtein" assert levenshtein(s1, s2) == 8
Methods¶
- levenshtein.has_c() bool¶
Checks if the C-backend is available.
- Returns:
Trueif the C-backend is available, otherwiseFalse.- Return type:
bool
- levenshtein.is_c() bool¶
Checks if the C-backend is currently used.
- Returns:
Trueif the C-backend is used, otherwiseFalse.- Return type:
bool
- levenshtein.switch_to_c() None¶
Switches the implementation to the C-backend.
- Raises:
NotSupportedBackendError – If the C-backend is not supported.
- levenshtein.has_python() bool¶
Checks if the Python-backend is available.
- Returns:
Always
True, as the Python-backend is available by default.- Return type:
bool
- levenshtein.is_python() bool¶
Checks if the Python-backend is currently used.
- Returns:
Trueif the Python-backend is used, otherwiseFalse.- Return type:
bool
- levenshtein.switch_to_python() None¶
Switches the implementation to the Python-backend.