Iterarea prin dicționare
Odată ce datele JSON sunt încărcate într-un dicționar, poți folosi instrumentele built-in din Python pentru a itera prin cheile și valorile sale.
Fișierul "nested_school_scores.json" a fost citit într-un dicționar stocat în variabila raw_testing_scores, care are următoarea structură:
{
"01M539": {
"street_address": "111 Columbia Street",
"city": "Manhattan",
"scores": {
"math": 657,
"reading": 601,
"writing": 601
}
}, ...
}
Acest exercițiu face parte din cursul
ETL și ELT în Python
Exercițiu interactiv practic
Încearcă acest exercițiu completând acest cod de exemplu.
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])