We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aef86a8 commit a77de02Copy full SHA for a77de02
algorithms/strings/levenstein.py
@@ -0,0 +1,9 @@
1
+def distance_levenstein(a, b):
2
+ f = [[(i+j) if i*j == 0 else 0 for j in range(len(b)+1)] for i in range(len(a) + 1)]
3
+ for i in range(1, len(a) + 1):
4
+ for j in range(1, len(b) + 1):
5
+ if a[i-1] == b[j-1]:
6
+ f[i][j] = f[i-1][j-1]
7
+ else:
8
+ f[i][j] = 1 + min(f[i-1][j], f[i][j-1], f[i-1][j-1])
9
+ return f[len(a)][len(b)]
0 commit comments