私信  •  关注

Soner Say

Soner Say 最近创建的主题
Soner Say 最近回复了

它是这样的:0,4,8,所以不需要第二个for循环。

你已经知道号码在哪里了。(i+1,i+2,i+3)我是学生的名字。

list1=['student1',10,20,40,'student2',20,20,40,'student3',20,30,40,'student4',20,10,30]
list2=[]
for i in range(0, len(list1), 4):
    list2.append(list1[i])
    sum = list1[i+1]+list1[i+2]+list1[i+3]
    list2.append(sum)
print(list2)