Created
December 10, 2018 21:52
-
-
Save decretist/f6439bf9e4505ed95e2f6d1079c04428 to your computer and use it in GitHub Desktop.
Demo for use of Python Levenshtein Hamming distance function for Jordan M
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
#!/usr/local/bin/python3 | |
# | |
# Paul Evans ([email protected]) | |
# 24 November 2018 | |
# 8 December 2018 | |
# 9 December 2018 | |
# 10 December 2018 | |
# | |
import Levenshtein | |
import re | |
# | |
def main(): | |
list_Sg = listify(re.split('\W', open('./Sg.txt', 'r').read())) | |
list_edF = listify(re.split('\W', open('./edF.txt', 'r').read())) | |
dedup(list_Sg, list_edF) | |
# | |
for Sg_word in list_Sg: | |
for edF_word in list_edF: | |
if (len(Sg_word) == len(edF_word)): | |
if (Levenshtein.hamming(Sg_word, edF_word) == 1): | |
print(Sg_word, edF_word) | |
# | |
def listify(words): | |
list = [] | |
for word in words: | |
if word: | |
word = word.lower() | |
if word not in list: # add it | |
list.append(word) | |
else: | |
pass | |
list.sort() | |
return(list) | |
# | |
def dedup(list_A, list_B): | |
dups = [] | |
for word in list_A: | |
if word in list_B: | |
dups.append(word) | |
else: | |
pass | |
for dup in dups: | |
list_A.remove(dup) | |
list_B.remove(dup) | |
# | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment