gpt4 book ai didi

python - '类型错误 : 'NoneType' object is not subscriptable' about lists

转载 作者:行者123 更新时间:2023-11-28 22:15:32 25 4
gpt4 key购买 nike

这个错误是什么意思?

这是我的代码:

import csv
from statistics import mean

averages = list()
sorted_averages = list()
dic = dict()
with open('first.csv') as fopen:
reader = csv.reader(fopen)
for line in reader:
name = line[0]
line = line[1:]
counter = 0
for i in line:
i = float(i)
line[counter] = i
counter += 1
average = mean(line)
averages.append(average)
dic[name] = average
for i in range(0, len(averages)):
maxi = 0
maxi1 = 0
for number in averages:
if number > maxi:
maxi = number
elif number == maxi:
maxi = number
maxi1 = number
else:
maxi = maxi
sorted_averages.append(maxi)
averages.remove(maxi)
del(averages)
insorted_averages = sorted_averages.reverse()
for z in insorted_averages[:3]:
print(z)

我已将我的列表从最大到最小排序。现在我想打印 3 个值(value)平均值,但我得到了那个错误。我已经完成了将 3 更改为 -4,但它也没有用

最佳答案

.reverse() 就地反转您的列表并返回 None:

sorted_averages = list(range(3))
insorted_averages = sorted_averages.reverse()
print(insorted_averages)

insorted_averages 现在是 Nonesorted_averages 是相反的......

mutable sequence types 下的 python 文档中阅读 (4) .

关于python - '类型错误 : 'NoneType' object is not subscriptable' about lists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52816850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com