Skip to content

Files

Latest commit

 

History

History

levenshtein_distance

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Calculates the Levenshtein distance between two strings.
The Levenshtein distance is defined as the minimum amount of
single-character edits (either removing a character, adding a
character, or changing a character) necessary to transform a source
string into a target string.

Input:
    source: The string you begin with.
    target: The string to transform into.

Output:
    The Levenshtein distance between the source and target.

Example:
    "electron" can be transformed into "neutron" by removing the
    "e", turning the "l" into "n", and turning the "c" into "u".
    >>> levenshtein("electron", "neutron")
    3