对于给定的用户输入,通过Enchant模块获得相似的单词。
null
Enchant
是python中的一个模块,用于检查单词的拼写,提供更正单词的建议。此外,给出了单词的反义词和同义词。它检查字典中是否有单词。还可以添加其他词典,如(“en_UK”)、(“en_CA”)、(“en_GB”)等。
要安装enchant:
pip install pyenchant
例如:
Input : Helo Output : Hello, Help, Hero, Helot, Hole Input : Trth Output : Truth, Trash, Troth, Trench
以下是实施情况:
# 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)) |
输出:
Enter word: aple ['pale', 'ale', 'ape', 'maple', 'ample', 'apple', 'plea', 'able', 'apse']
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END