开始使用免费开始使用

遍历字典

当 JSON 数据被加载到字典后,您可以使用 Python 的内置工具来遍历其键和值。

文件 "nested_school_scores.json" 已读取为字典,并存入变量 raw_testing_scores,其结构如下:

{
    "01M539": {
        "street_address": "111 Columbia Street",
        "city": "Manhattan",
        "scores": {
              "math": 657,
              "reading": 601,
              "writing": 601
        }
  }, ...
}

本练习是课程的一部分

使用 Python 的 ETL 和 ELT

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

raw_testing_scores_keys = []

# Iterate through the keys of the raw_testing_scores dictionary
for school_id in raw_testing_scores.____():
  	# Append each key to the raw_testing_scores_keys list
	raw_testing_scores_keys.append(____)
    
print(raw_testing_scores_keys[0:3])
编辑并运行代码