【问题标题】:An error happens in my wordnet python code: IndexError; List index out of range我的 wordnet python 代码中发生错误:IndexError;列表索引超出范围
【发布时间】:2020-09-09 15:56:58
【问题描述】:

我正在编写一些小代码,但错误

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)

【问题讨论】:

标签: python nltk wordnet


【解决方案1】:

显然,syns 不是长度至少为 1 的列表或元组。您是否尝试打印此变量以查看它是否包含值?

【讨论】:

    猜你喜欢
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 2020-09-04
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多