Skip to content

Commit

Permalink
Create Levenshtein_Edit_Distance.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kag22034 authored Mar 28, 2025
1 parent 67c6e65 commit 7269948
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Levenshtein_Edit_Distance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def edit_distance(str1, str2): #input is 2 strings that we will be comparing

# create a matrix that has length str2 + 1 columns and length str1 + 1 rows
D = [[0 for i in range(len(str2)+1)] for j in range(len(str1)+1)]

#initialize first row - how many deletions are needed to get an empty list
for i in range(len(str1)+1):
D[i][0] = i

#initialize first column - how many insertions to go from empty list to str2
for j in range(len(str2)+1):
D[0][j] = j

# Fill in rest of matrix with recursive case

0 comments on commit 7269948

Please sign in to comment.