valueerror - ValueError:“攻击”不在列表中
问题描述
import json
i = 1
file_name = 'PolitiFact_Fake_' + str(i) + '-Webpage.json'
with open(file_name, 'r') as fp:
obj = json.load(fp)
text = obj['text']
length = len(text)
wordlist = text.split()
wordfreq = []
for w in wordlist:
wordfreq.append(wordlist.count(w))
lengthslova = len(wordlist)
wordfind = 'in'
indexword = wordlist.index(wordfind)
indexfreq = wordfreq[indexword]
findword = [wordfreq, wordlist]
findwordt = [[row[j] for row in findword] for j in range(lengthslova)]
wordfind = "attacks"
indexfreq = 0
if indexword != ValueError:
indexword = wordlist.index(wordfind)
indexfreq = wordfreq[indexword]
findword = [wordfind, indexfreq]
indexfreq = wordfreq[indexword]
findword = [wordfind, indexfreq]
print('The freq of word ' + str(wordfind) + ':', indexfreq)
else:
indexfreq = 0
findword = [wordfind, indexfreq]
print('The freq of word ' + str(wordfind) + ':', indexfreq)
我不断收到此错误:
ValueError:“攻击”不在列表中
解决方案
推荐阅读
- java - JGIT - 获取每个授权的私人项目
- c# - 转换为双精度不允许小数点后为零
- r - R:通过将另一个向量“b”中的值添加到向量“a”中的前一个元素来增加向量“a”中元素的值
- javascript - 通过创建按钮将数据保存到 chrome 存储
- jquery - 引导程序:未捕获的类型错误:无法读取未定义的属性“fn”
- spring - 如何编辑或更改 Spring 参数扩展?
- android - 如何使用firebase在导航抽屉中正确退出谷歌
- google-workspace - GMail 和 IMAP 访问
- scipy - “Newton-CG 方法需要 Jacobian”问题仍然存在于 trust-ncg
- java - 调用在迭代中创建的数组