侧边栏壁纸
  • 累计撰写 28 篇文章
  • 累计收到 1 条评论

Python抽取分数超过60的学生

2023-11-12 / 0 评论 / 526 阅读
print('1111')
示例数据

students = [
{'name': 'Alice', 'score': 78},
{'name': 'Bob', 'score': 56},
{'name': 'Charlie', 'score': 84},
{'name': 'Dave', 'score': 92}
]

这个例子中,filter_students_by_score 函数通过列表推导式(list comprehension)筛选出那些分数超过60的学生记录。
抽取分数超过60的学生

def filter_students_by_score(data):
return [student for student in data if student['score'] > 60]

filtered_students = filter_students_by_score(students)

打印结果

for student in filtered_students:
print(student)


扫描二维码,在手机上阅读