Skip to content

Instantly share code, notes, and snippets.

@DanBrink91
Created May 19, 2017 19:03
Show Gist options
  • Save DanBrink91/487d296a3956f4d75e3dd5a247710012 to your computer and use it in GitHub Desktop.
Save DanBrink91/487d296a3956f4d75e3dd5a247710012 to your computer and use it in GitHub Desktop.
Finding animals with names close to RPG classes
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