始める無料で始める

辞書を反復処理する

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])
コードを編集して実行