ComeçarComece gratuitamente

Iteração sobre dicionários

Depois que os dados JSON são carregados em um dicionário, você pode aproveitar as ferramentas integradas do Python para iterar sobre suas chaves e valores.

O arquivo "nested_school_scores.json" foi lido em um dicionário armazenado na variável raw_testing_scores, que tem o seguinte formato:

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

Este exercício faz parte do curso

ETL e ELT em Python

Ver Curso

Exercício interativo prático

Experimente este exercício preenchendo este código de exemplo.

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 e executar código