遍歷字典
當你把 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])