def levenshtein(string1, string2):
"""
Computes the Levenshtein distance between two strings.
Levenshtein distance computes the minimum cost of transforming one string into the other. Transforming a string
is carried out using a sequence of the following operators: delete a character, insert a character, and
substitute one character for another.
Args:
string1,string2 (str): Input strings
Returns:
Levenshtein distance (int)
Raises:
TypeError : If the inputs are not strings
Examples:
>>> levenshtein('a', '')
1
>>> levenshtein('example', 'samples')
3
>>> levenshtein('levenshtein', 'frankenstein')
6
Note:
This implementation internally uses python-levenshtein package to compute the Levenshtein distance
"""
# input validations
utils.sim_check_for_none(string1, string2)
utils.sim_check_for_string_inputs(string1, string2)
# using Levenshtein library
return Levenshtein.distance(string1, string2)
评论列表
文章目录