How to find the most similar word in a list in python

Use difflib:

difflib.get_close_matches(word, ['car', 'animal', 'house', 'animation'])

As you can see from perusing the source, the “close” matches are sorted from best to worst.

>>> import difflib
>>> difflib.get_close_matches('anlmal', ['car', 'animal', 'house', 'animation'])
['animal']

Leave a Comment