我的wordnet python代码中发生了一个错误:IndexError;列表索引超出范围

2024-10-01 07:39:27 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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)


Tags: ofthe代码youinputstringiscorpus