2024-05-19 06:46:11 发布
网友
我想用
from PyDictionary import PyDictionary word = input("enter a word: ") dictionary = PyDictionary(word) check = dictionary.getMeanings() print(check) input("press enter to exit")
如果有使用PyDictionary,则可以检查单词的含义并将返回值包装在bool函数中:
PyDictionary
bool
from PyDictionary import PyDictonary dictionary = PyDictionary() valid_word = bool(dictionary.meaning("hdaoij")) # False valid_word = bool(dictionary.meaning("hello")) # True
或
valid_word = bool(dictionary.meaning(input("enter a word: ")))
否则,我将在@RoadJDK的答案中使用enchant中的check函数
enchant
check
我刚才看到这篇文章: How to check if a word is an English word with Python?
>>> import enchant >>> d = enchant.Dict("en_US") >>> d.check("Hello") True >>> d.check("Helo") False >>> d.suggest("Helo") ['He lo', 'He-lo', 'Hello', 'Helot', 'Help', 'Halo', 'Hell', 'Held', 'Helm', 'Hero', "He'll"] >>>
如果有使用
PyDictionary
,则可以检查单词的含义并将返回值包装在bool
函数中:或
否则,我将在@RoadJDK的答案中使用
enchant
中的check
函数我刚才看到这篇文章: How to check if a word is an English word with Python?
相关问题 更多 >
编程相关推荐