ComenzarEmpieza gratis

Iterar sobre diccionarios

Una vez cargados los datos JSON en un diccionario, puedes aprovechar las herramientas integradas de Python para iterar sobre sus claves y valores.

El archivo "nested_school_scores.json" se ha leído en un diccionario almacenado en la variable raw_testing_scores, que tiene la siguiente forma:

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

Este ejercicio forma parte del curso

ETL y ELT en Python

Ver curso

Ejercicio interactivo práctico

Pruebe este ejercicio completando este código de muestra.

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])
Editar y ejecutar código