我想过使用
from PyDictionary import PyDictionary
word = input("enter a word: ")
dictionary = PyDictionary(word)
check = dictionary.getMeanings()
print(check)
input("press enter to exit")
我想过使用
from PyDictionary import PyDictionary
word = input("enter a word: ")
dictionary = PyDictionary(word)
check = dictionary.getMeanings()
print(check)
input("press enter to exit")
前段时间看到这个帖子: 如何用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
函数中:
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 的回答中使用check
in 中的函数enchant