字典列表(常见结构)
16.9 字典列表(常见结构)
列表里套字典是数据处理最常见结构,类似 Excel 多行表。
每条记录一个 dict,字段名作键。
学生列表
# ========================================
# 示例:字典列表
# 说明:类似 JSON 数组
# ========================================
students = [
{'name': '小明', 'score': 92},
{'name': '小红', 'score': 88},
{'name': '小刚', 'score': 76}
]
for stu in students:
print(stu['name'], stu['score'])
# 找最高分
best = max(students, key=lambda s: s['score'])
print('最高分', best)