def levenshtein_dist(t1_fname, t2_fname):
 (len_t1_fname, len_t2_fname) = (len(t1_fname), len(t2_fname))
 if (len_t1_fname > len_t2_fname):
  (t1_fname, t2_fname) = (t2_fname, t1_fname)
  (len_t1_fname, len_t2_fname) = (len_t2_fname, len_t1_fname)
 current = range((len_t1_fname + 1))
 for i in xrange(1, (len_t2_fname + 1)):
  (previous, current) = (current, ([i] + ([0] * len_t1_fname)))
  for j in xrange(1, (len_t1_fname + 1)):
   (add, delete) = ((previous[j] + 1), (current[(j - 1)] + 1))
   change = previous[(j - 1)]
   if (t1_fname[(j - 1)] != t2_fname[(i - 1)]):
    change += 1
   current[j] = min(add, delete, change)
 return current[len_t1_fname]

def levenshtein_dist ( t1_fname , t2_fname ) : ( len_t1_fname , len_t2_fname ) = ( len ( t1_fname ) , len ( t2_fname ) ) if ( len_t1_fname > len_t2_fname ) : ( t1_fname , t2_fname ) = ( t2_fname , t1_fname ) ( len_t1_fname , len_t2_fname ) = ( len_t2_fname , len_t1_fname ) current = range ( ( len_t1_fname + 1 ) ) for i in xrange ( 1 , ( len_t2_fname + 1 ) ) : ( previous , current ) = ( current , ( [ i ] + ( [ 0 ] * len_t1_fname ) ) ) for j in xrange ( 1 , ( len_t1_fname + 1 ) ) : ( add , delete ) = ( ( previous [ j ] + 1 ) , ( current [ ( j - 1 ) ] + 1 ) ) change = previous [ ( j - 1 ) ] if ( t1_fname [ ( j - 1 ) ] != t2_fname [ ( i - 1 ) ] ) : change += 1 current [ j ] = min ( add , delete , change ) return current [ len_t1_fname ]
calculates the levenshtein distance between a and b .