AI题库 · Python编程五级题库
题目分享 #16263
班级组织户外活动,老师要统计带水杯的同学名单。已知学生信息列表为:
students = [{"name": "小明", "has_cup": True}, {"name": "小红", "has_cup": False}, {"name": "小刚", "has_cup": True}],正确的推导式是?( )
A
[student["name"] for student in students if has_cup]
B
[name for student in students where student.has_cup]
C
[student["name"] for student in students if student["has_cup"]]
D
[student.name for student in students when student.has_cup]
AI题库 · 编程考级与信奥赛真题库
查看答案 →
复制链接后可在微信、QQ、小红书等平台粘贴分享;答案与解析在题目页。