Enchant is a module in Python, which is used to check the spelling of a word, gives suggestions to correct words. Also, gives antonym and synonym of words. It checks whether a word exists in the dictionary or not.
Enchant can also be used to check the spelling of words. The check() method returns True if the passed word is present in the language dictionary, else it returns False. This functionality of the check() method can be used to spell check words.
The suggest() method is used to suggest the correct spelling of the incorrectly spelled word.
Python3
import enchant
dict = enchant. Dict ( "en_US" )
words = [ "cmputr" , "watr" , "study" , "wrte" ]
misspelled = []
for word in words:
if dict .check(word) = = False :
misspelled.append(word)
print ( "The misspelled words are : " + str (misspelled))
for word in misspelled:
print ( "Suggestion for " + word + " : " + str ( dict .suggest(word)))
|
Output :
The misspelled words are : ['cmputr', 'watr', 'wrte']
Suggestion for cmputr : ['computer']
Suggestion for watr : ['wart', 'watt', 'wat', 'war', 'water', 'wat r']
Suggestion for wrte : ['rte', 'write', 'wrote', 'wert', 'wite', 'w rte']