def levenshtein_distance(a, b):
    """Compute the Levenshtein edit distance between the sequences a and b."""
    m = len(a) + 1
    n = len(b) + 1

    d = [[0]*n for _ in range(m)]
    for i in range(m): d[i][0] = i # deletion
    for j in range(n): d[0][j] = j # insertion

    for i in range(1, m):
        for j in range(1, n):
            if a[i-1] == b[j-1]:
                d[i][j] = d[i-1][j-1]
            else:
                d[i][j] = min(d[i-1][j] + 1, # deletion
                              d[i][j-1] + 1, # insertion
                              d[i-1][j-1] + 1) # substitution
    return d[m-1][n-1]