我想看看这个词是否存在于词典中,或者没有使用PyDictionary库。我有以下代码,但我可以看到一些错误,如“列表索引超出范围”,我无法理解。我是python新手
def fst_wrd(exmp):
from PyDictionary import PyDictionary
dictionary=PyDictionary()
try:
var = (dictionary.meaning(exmp))
except:
if var == None:
return(False)
else:
return (True)
for exmp in my_list:
result = fst_wrd(exmp)
if result == True:
print(exmp, "is dict")
else:
print(exmp, "not dict")
假设我有一个列表mylist=[“on”,“carrot”,“hello”,“tunc”]。我得到的错误是list:index超出范围
尝试使用
meaning(word, disable_errors=True)
禁用错误消息。您可以尝试以下代码:相关问题 更多 >
编程相关推荐