From 7269948f5fb131d8bf2bc04a2a222d6cebccc8e6 Mon Sep 17 00:00:00 2001 From: Kieren A Ghidella Date: Fri, 28 Mar 2025 14:22:11 -0400 Subject: [PATCH] Create Levenshtein_Edit_Distance.py --- Levenshtein_Edit_Distance.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Levenshtein_Edit_Distance.py diff --git a/Levenshtein_Edit_Distance.py b/Levenshtein_Edit_Distance.py new file mode 100644 index 0000000..1d98ac6 --- /dev/null +++ b/Levenshtein_Edit_Distance.py @@ -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