如何解决我的wordnet python代码中发生错误:IndexError;列表索引超出范围
IndexError: list index out of range
总是在执行最后一行代码后出现,有帮助吗?
from nltk.corpus import wordnet # this is where you load the wordnet corpus
user_input = input("What should I reverse,user?") # this is where you get the items for the string
str = user_input # this is the initial string
stringlength = len(str) # this is where you calculate length of the list
slicedString = str[stringlength::-1] # this is where you start slicing
syns = wordnet.synsets(slicedString) # this gives the reversed word to the dictionary
print(syns[0].deFinition()) # this prints the meaning (if there is one)
我已经在书中寻找答案,但是没有任何效果。 (PyCharm Edu 4.0)
解决方法
显然,syns
不是长度至少为1的列表或元组。您是否尝试过打印此变量以查看其是否包含值?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。