leveinshtein.py
def leveinshtein_distance(source,target):
	"""
	Implement leveintein distance algorithm as described in the reference
	"""
	#Step 1
	s_len=len(source)
	t_len=len(target)
	cost=0
	if(s_len==0):
		return t_len
	if(t_len==0):
		return s_len
	print("Dimensions:\n\tN:%d\n\tM:%d"%(s_len,t_len))
	#Step 2
	matrix=[[0 for _ in range(0,t_len+1)] for _ in range(0, s_len+1)]
	#Initialize first row 0..s_len
	for idx in range(0,s_len+1):
		matrix[idx][0]=idx
	#Initialize the first column 0..t_len
	for idx in range(0, t_len+1):
		matrix[0][idx]=idx
	print("===Original===")
	print_matrix(matrix,source,target)
	#Step 3
	for i in range(1,s_len+1):
		ch=source[i-1]
		#print(ch)
		#Step 4
		for j in range(1,t_len+1):
			#print(">%s"%target[j-1])
			#Step 5
			if ch==target[j-1]:
				cost=0
			else:
				cost=1
			#Step 6
			
			#print("(i,j)=>(%d,%d)"%(i,j))
			#print(matrix[i][j])
			matrix[i][j]=minimum(
				matrix[i-1][j]+1,
				matrix[i][j-1]+1,
				matrix[i-1][j-1]+cost
			)
	print("===Final Matrix===")
	print_matrix(matrix,source,target)
	return matrix[s_len-1][t_len-1]

	Implement leveintein distance algorithm as described in the reference
	
Implement leveintein distance algorithm as described in the reference
Implement leveintein distance algorithm as described in the reference
def leveinshtein_distance(source,target):
	s_len=len(source)
	t_len=len(target)
	cost=0
	if(s_len==0):
		return t_len
	if(t_len==0):
		return s_len
	print("Dimensions:\n\tN:%d\n\tM:%d"%(s_len,t_len))
	matrix=[[0 for _ in range(0,t_len+1)] for _ in range(0, s_len+1)]
	for idx in range(0,s_len+1):
		matrix[idx][0]=idx
	for idx in range(0, t_len+1):
		matrix[0][idx]=idx
	print("===Original===")
	print_matrix(matrix,source,target)
	for i in range(1,s_len+1):
		ch=source[i-1]
		for j in range(1,t_len+1):
			if ch==target[j-1]:
				cost=0
			else:
				cost=1
			matrix[i][j]=minimum(
				matrix[i-1][j]+1,
				matrix[i][j-1]+1,
				matrix[i-1][j-1]+cost
			)
	print("===Final Matrix===")
	print_matrix(matrix,source,target)
	return matrix[s_len-1][t_len-1]
def leveinshtein_distance ( source , target ) : s_len = len ( source ) t_len = len ( target ) cost = 0 if ( s_len == 0 ) : return t_len if ( t_len == 0 ) : return s_len print ( "Dimensions:\n\tN:%d\n\tM:%d" % ( s_len , t_len ) ) matrix = [ [ 0 for _ in range ( 0 , t_len + 1 ) ] for _ in range ( 0 , s_len + 1 ) ] for idx in range ( 0 , s_len + 1 ) : matrix [ idx ] [ 0 ] = idx for idx in range ( 0 , t_len + 1 ) : matrix [ 0 ] [ idx ] = idx print ( "===Original===" ) print_matrix ( matrix , source , target ) for i in range ( 1 , s_len + 1 ) : ch = source [ i - 1 ] for j in range ( 1 , t_len + 1 ) : if ch == target [ j - 1 ] : cost = 0 else : cost = 1 matrix [ i ] [ j ] = minimum ( matrix [ i - 1 ] [ j ] + 1 , matrix [ i ] [ j - 1 ] + 1 , matrix [ i - 1 ] [ j - 1 ] + cost ) print ( "===Final Matrix===" ) print_matrix ( matrix , source , target ) return matrix [ s_len - 1 ] [ t_len - 1 ]
Implement leveintein distance algorithm as described in the reference
Implement leveintein distance algorithm as described in the reference
"""
	Implement leveintein distance algorithm as described in the reference
	""" #Step 1
 #Step 2
 #Initialize first row 0..s_len
 #Initialize the first column 0..t_len
 #Step 3
 #print(ch)
 #Step 4
 #print(">%s"%target[j-1])
 #Step 5
 #Step 6
 #print("(i,j)=>(%d,%d)"%(i,j))
 #print(matrix[i][j])

source
target