You're likely a better developer than I am, but I breezed past something in the Python Docs the other day that might offer some ideas...
Maybe get_close_matches() in difflib as an example?
I really haven't taken a close look at it, but you might find some of the logic worth looking at.
Best regards,
Chris