def edit_distance(str1, str2):
    """
    Compute the Levenshtein distance between @p str1 and @p str2.

    This is evolved from the Wagner-Fischer Dynamic Programming solution that
    has been posted in multiple places all over Google.
    """
    if len(str1) < len(str2):
        str1, str2 = str2, str1
    if len(str2) == 0:
        return len(str1)
    prev_row = list(range(len(str2) + 1))
    for i, char1 in enumerate(str1):
        cur_row = [i + 1]
        for j, char2 in enumerate(str2):
            insertions = prev_row[j + 1] + 1
            deletions = cur_row[j] + 1
            substitutions = prev_row[j]
            if char1 != char2:
                substitutions += 1
            cur_row.append(min(insertions, deletions, substitutions))
        prev_row = cur_row
    return prev_row[-1]
