ComeçarComece de graça

Reading the data from the CSV

Leverage the Python CSV module from the standard library and load the data into a list of dictionaries.

It may help to refer back to the Chapter 4 exercise in which you did something similar.

Este exercício faz parte do curso

Introduction to Databases in Python

Ver curso

Instruções do exercício

  • Create an empty list called values_list.
  • Iterate over the rows of csv_reader with a for loop, creating a dictionary called data for each row and append it to values_list.
    • Within the for loop, row will be a list whose entries are 'state' , 'sex', 'age', 'pop2000' and 'pop2008' (in that order).

Exercício interativo prático

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

# Create an empty list: values_list
values_list = ____

# Iterate over the rows
for row in csv_reader:
    # Create a dictionary with the values
    data = {____: row[____], ____: row[____], ____:____, ____: ____,
            ____: ____}
    # Append the dictionary to the values list
    values_list.append(____)
Editar e executar o código