(seq1, seq2, limit=None)
return thisrow[len(seq2) - 1]
Returns the Levenshtein edit distance between two strings.
Returns the Levenshtein edit distance between two strings.
Returns the Levenshtein edit distance between two strings .
def levenshtein(seq1, seq2, limit=None):
    """Returns the Levenshtein edit distance between two strings.
    """

    oneago = None
    thisrow = range(1, len(seq2) + 1) + [0]
    for x in xrange(len(seq1)):
        # Python lists wrap around for negative indices, so put the
        # leftmost column at the *end* of the list. This matches with
        # the zero-indexed strings and saves extra calculation.
        oneago, thisrow = thisrow, [0] * len(seq2) + [x + 1]
        for y in xrange(len(seq2)):
            delcost = oneago[y] + 1
            addcost = thisrow[y - 1] + 1
            subcost = oneago[y - 1] + (seq1[x] != seq2[y])
            thisrow[y] = min(delcost, addcost, subcost)

        if limit and x > limit and min(thisrow) > limit:
            return limit + 1

    return thisrow[len(seq2) - 1]
def levenshtein ( seq1 , seq2 , limit = None ) : oneago = None thisrow = range ( 1 , len ( seq2 ) + 1 ) + [ 0 ] for x in xrange ( len ( seq1 ) ) : # Python lists wrap around for negative indices, so put the # leftmost column at the *end* of the list. This matches with # the zero-indexed strings and saves extra calculation. oneago , thisrow = thisrow , [ 0 ] * len ( seq2 ) + [ x + 1 ] for y in xrange ( len ( seq2 ) ) : delcost = oneago [ y ] + 1 addcost = thisrow [ y - 1 ] + 1 subcost = oneago [ y - 1 ] + ( seq1 [ x ] != seq2 [ y ] ) thisrow [ y ] = min ( delcost , addcost , subcost ) if limit and x > limit and min ( thisrow ) > limit : return limit + 1 return thisrow [ len ( seq2 ) - 1 ]