Skip to content
Related Articles

Related Articles

Python – Spelling checker using Enchant
  • Last Updated : 26 May, 2020

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 dictionary or not.

Enchant can also be used to check 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.




# import the enchant module
import enchant
  
# create dictionary for the language
# in use(en_US here)
dict = enchant.Dict("en_US")
  
# list of words
words = ["cmputr", "watr", "study", "wrte"]
  
# find those words that may be misspelled 
misspelled =[]
for word in words:
    if dict.check(word) == False:
        misspelled.append(word)
print("The misspelled words are : " + str(misspelled))
  
# suggest the correct spelling of
# the missplelled words
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']

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :