human
What is a code to edit distance and LCS ( Longest Common Subsequence ) and the other steps required given the following:
Edit distance and LCS ( Longest Common Subsequence ) | Python 3 program to find Edit Distance ( when only two operations are allowed , insert and delete ) using LCS ..
Find LCS.
Edit distance is delete operations + insert operations ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to edit distance and LCS ( Longest Common Subsequence ) and the other steps required.
 def editDistanceWith2Ops ( X , Y ) :
	m = len ( X )
	n = len ( Y )
	L = [ [ 0 for x in range ( n + 1 ) ] for y in range ( m + 1 ) ]
	for i in range ( m + 1 ) :
		for j in range ( n + 1 ) :
			if ( i == 0 or j == 0 ) :
				L [ i ] [ j ] = 0
			elif ( X [ i - 1 ] == Y [ j - 1 ] ) :
				L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1
			else :
				L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] )
	lcs = L [ m ] [ n ]
	return ( m - lcs ) + ( n - lcs )
if __name__ == " _ _ main _ _ " :
	X = " abc "
	Y = " acd "
	print ( editDistanceWith2Ops ( X , Y ) )