Answer:
Step-by-step explanation:
The following code takes in the two parameters s1 and s2 and returns the Levenshtein distance of the two strings passed.
def editDistance(s1, s2):
m = len(s1) + 1
n = len(s2) + 1
arr = {}
for x in range(m):
arr[x, 0] = x
for y in range(n):
arr[0, y] = y
for x in range(1, m):
for y in range(1, n):
proc = 0 if s1[x - 1] == s2[y - 1] else 1
arr[x, y] = min(arr[x, y - 1] + 1, arr[x - 1, y] + 1, arr[x - 1, y - 1] + proc)
return arr[x, y]