MulaiMulai sekarang secara gratis

Iterating over dictionaries

Once JSON data is loaded into a dictionary, you can leverage Python's built-in tools to iterate over its keys and values.

The "nested_school_scores.json" file has been read into a dictionary stored in the raw_testing_scores variable, which takes the following form:

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

Latihan ini adalah bagian dari kursus

ETL and ELT in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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])
Edit dan Jalankan Kode