API Reference¶
lev ¶
An extremely fast Python library for the Levenshtein distance and similarity ratio.
distance
builtin
¶
Levenshtein edit distance between two strings.
The distance is the minimum number of single-character insertions,
deletions, or substitutions required to transform s1 into s2.
Characters are counted as Unicode code points, so an accented letter or an emoji counts as one character.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s1
|
str
|
First input string. |
required |
s2
|
str
|
Second input string. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Non-negative integer edit distance. |
Examples:
ratio
builtin
¶
Calculate how similar two strings are, as a score from 0.0 to 1.0.
A score of 1.0 means the strings are identical, and 0.0 means they
have no character in common. In between, the score is the share of
characters the two strings have in common, known as the indel similarity
ratio:
where \(\mathrm{LCS}\) is the length of the longest common subsequence and \(|s|\) is the length of \(s\).
Characters are counted as Unicode code points, so an accented letter or an emoji counts as one character.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s1
|
str
|
First input string. |
required |
s2
|
str
|
Second input string. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Similarity score between |
Examples: