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
}
}, ...
}
This exercise is part of the course
ETL and ELT in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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])