```python
复制
def sort_students(students, order): sorted_students = sorted(students, key=lambda x: (x[1], students.index(x)), reverse=order) return sorted_students
students = [('Alice', 85), ('Bob', 75), ('Charlie', 90), ('David', 75)] order = 0 sorted_students = sort_students(students, order)
for student in sorted_students: print(student[0], student[1])
```
在这个示例中,我们定义了一个sort_students
函数,它接受学生信息列表和排序顺序作为参数,并根据成绩从高到低或从低到高对学生进行排序。我们使用sorted
函数并指定key
参数来实现按照特定规则排序。最后打印出排好序的学生信息。