知识点:
list
分组后重新构建嵌套数组
多维数组排序
import operator
stu_list = [["apple", 75], ["李四", 97], ["张三", 77], ["mary", 89], ["jack", 90], ["马丽", 89], ["王强", 75], ["dog", 7],
["mark", 14], ["cindy", 66], ["bb", 100], ["rose", 79]]
group_list = [
[], [], [], [], []
]
for i in stu_list:
if i[1] >= 90:
group_list[0].append(i)
group_list[0].sort(key=operator.itemgetter(1), reverse=True)
elif i[1] >= 80:
group_list[1].append(i)
group_list[1].sort(key=operator.itemgetter(1), reverse=True)
elif i[1] >= 70:
group_list[2].append(i)
group_list[2].sort(key=operator.itemgetter(1), reverse=True)
elif i[1] >= 60:
group_list[3].append(i)
group_list[3].sort(key=operator.itemgetter(1), reverse=True)
else:
group_list[4].append(i)
group_list[4].sort(key=operator.itemgetter(1), reverse=True)
for group in group_list:
print(group)
执行结果: