This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def levenshtein_distance(s1, s2): | |
# Initialize dynamic programming table using list comprehension | |
dp = [[i + j if i * j == 0 else 0 for j in range(len(s2) + 1)] for i in range(len(s1) + 1)] | |
# Fill DP table | |
for i in range(1, len(s1) + 1): | |
for j in range(1, len(s2) + 1): | |
cost = 0 if s1[i - 1] == s2[j - 1] else 1 | |
dp[i][j] = min( | |
dp[i - 1][j] + 1, # Deletion |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import nltk | |
nltk.download('words') | |
from nltk.corpus import words | |
# Step 1: Build the dictionary | |
word_list = words.words() | |
# Assign primes to letters | |
primes = [ |