28Edit Distance

    Harddynamic programmingstrings

    Write edit_distance(a, b) that returns the smallest number of single-character edits needed to turn a into b.

    An edit is inserting a character, deleting a character, or replacing one character with another. For example kitten → sitting takes 3 edits.

    Examples

    Example 1
    >>> edit_distance('kitten', 'sitting')
    3
    Example 2
    >>> edit_distance('horse', 'ros')
    3

    Run examples checks the 2 examples above. Submit runs all 7 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write edit_distance in the editor, then run the examples. Use print() freely: its output is shown for each test.