问题描述
我正在尝试基于图形的文本摘要。
sentences_rank_frek=[]
for sentence in copy_sent:
for word in sentence:
if word in freq:
sentences_rank_frek[sentence]+=freq[copy_sent[sentence][word]]
此代码报错:列表索引必须是整数或切片,而不是列表 我可以显示这个频率[copy_sent[0][1]] = 4
解决方法
在尝试访问 sentence
时,您需要检查 sentences_rank_frek[sentence]
变量的类型是什么。我猜......这是一个句子,所以它必须是一个字符串或字符串列表。您正在尝试使用字符串访问列表中的索引。
您可能希望 sentences_rank_frek=[]
是字典而不是数组。