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 s1 and s2.

Return type:

int

Raises:

TypeError – If s1 or s2 are 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:

True if the C-backend is available, otherwise False.

Return type:

bool

levenshtein.is_c() bool

Checks if the C-backend is currently used.

Returns:

True if the C-backend is used, otherwise False.

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:

True if the Python-backend is used, otherwise False.

Return type:

bool

levenshtein.switch_to_python() None

Switches the implementation to the Python-backend.