Aan de slagGa gratis aan de slag

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
        }
  }, ...
}

Deze oefening maakt deel uit van de cursus

ETL and ELT in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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])
Code bewerken en uitvoeren