此错误是什么意思?
这是我的代码:
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个均值,但出现错误。我已经完成了将3更改为-4的操作,但是它也没有起作用
答案 0 :(得分:4)
.reverse()
就地反转您的列表并返回None
:
sorted_averages = list(range(3))
insorted_averages = sorted_averages.reverse()
print(insorted_averages)
insorted_averages
现在为None
。 sorted_averages
被颠倒了...
在mutable sequence types下的python文档中阅读(4)。