students = [
{"name": "张三", "id": "1001", "score": 92},
{"name": "李四", "id": "1002", "score": 85},
{"name": "王五", "id": "1003", "score": 98},
{"name": "赵六", "id": "1004", "score": 76}
]
# 使用sorted()函数按成绩排序
sorted_students = sorted(students, key=lambda x: x['score'], reverse=True)
print("按成绩排序后的学生列表:")
for student in sorted_students:
print(f"姓名: {student['name']}, 学号: {student['id']}, 成绩: {student['score']}")
import json
with open('sorted_students.json', 'w') as f:
json.dump(sorted_students, f)