列表索引超出了更多单词的范围

2024-04-20 02:37:27 发布

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

from nltk.corpus import wordnet

s=0
file1 = open("File1.txt", "r")
file2 = open("features_mobile.txt","r")     
outputFile = open("File2.txt", "w")
list1, list2, list = [], [], []

list1 = [(wordnet.synsets(word)[0]) for word in file1.read().splitlines()]
list2 = [(wordnet.synsets(word)[0]) for word in file2.read().splitlines()]

如果File1.txt有3个以上的单词,我就会出错。 它的内容是这样的 照相机 透镜 处理器 电池 身体 对于这么多的单词,它给出了错误列表:inde超出范围 三个字就行了 我该怎么办??你知道吗


Tags: intxtforreadopen单词file1wordnet