Skip to content

Instantly share code, notes, and snippets.

@isidroamv
Created July 3, 2020 17:21
Show Gist options
  • Save isidroamv/fd246b2a2e0b12e15c74c12f2d34b4ca to your computer and use it in GitHub Desktop.
Save isidroamv/fd246b2a2e0b12e15c74c12f2d34b4ca to your computer and use it in GitHub Desktop.
def testWord(word, word_new):
isGreater = len(word_new) > len(word) + 1
isLower = len(word_new) < len(word) - 1
if isGreater or isLower:
return False
if len(word_new) > len(word):
length = len(word_new)
else:
length = len(word)
i_word = 0
i_word_new = 0
mismatch = 0
if len(word) == len(word_new):
while i_word < len(word):
if mismatch > 1:
return False
if word[i_word] != word_new[i_word]:
mismatch += 1
i_word += 1
elif len(word_new) > len(word):
while i_word_new < len(word_new):
if mismatch > 1:
return False
if i_word_new > len(word) - 1:
break
if word[i_word] != word_new[i_word_new]:
mismatch += 1
i_word_new += 1
continue
i_word += 1
i_word_new += 1
else:
while i_word < len(word):
if mismatch > 1:
return False
if i_word > len(word_new) - 1:
break
#print("---", word[i_word], word_new[i_word_new], mismatch)
if word[i_word] != word_new[i_word_new]:
mismatch += 1
i_word += 1
continue
i_word += 1
i_word_new += 1
if mismatch > 1:
return False
else:
return True
comp = [
["pale", "ple"],
["pales", "pale"],
["pale", "bale"],
["ssss", "pssss"],
["pssss", "ssss"],
["spsss", "psss"],
["pale", "bae"],
["pale", "palade"],
["pato", "ptos"],
["pato", "proto"]
]
for c in comp:
print(testWord(c[0], c[1]))
#print(testWord("patos", "ptos"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment