Get similar words suggestion using Enchant in Python

For the given user input, get similar words through Enchant module.

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. Other dictionaries can also be added, as, (“en_UK”), (“en_CA”), (“en_GB”) etc.

To install enchant :



pip install pyenchant

Examples :

Input : Helo
Output : Hello, Help, Hero, Helot, Hole

Input : Trth
Output : Truth, Trash, Troth, Trench

 
Below is the implementation :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to print the similar
# words using Enchant module
  
# Importing the Enchant module
import enchant
  
# Using 'en_US' dictionary
d = enchant.Dict("en_US")
  
# Taking input from user
word = input("Enter word: ")
  
d.check(word)
  
# Will suggest similar words
# form given dictionary
print(d.suggest(word))

chevron_right


Output :

Enter word: aple

['pale', 'ale', 'ape', 'maple', 'ample', 'apple', 'plea', 'able', 'apse']


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.