Created
May 19, 2017 19:03
-
-
Save DanBrink91/487d296a3956f4d75e3dd5a247710012 to your computer and use it in GitHub Desktop.
Finding animals with names close to RPG classes
This file contains 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 difflib | |
with open('animals.txt', 'r') as animal_file: | |
animals = [a.strip() for a in animal_file.readlines()] | |
with open('classes.txt', 'r') as class_file: | |
classes = [c.strip() for c in class_file.readlines()] | |
close_matches = [] | |
for c in classes: | |
closest = difflib.get_close_matches(c, animals, n=20, cutoff=0.7) | |
for close in closest: | |
close_matches.append((c, close)) | |
with open('output.txt', 'w') as out: | |
cs = ["%s -> %s\n" % (c[0], c[1]) for c in close_matches] | |
out.writelines(cs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment