Nov 9: Nested Data

Learning Objectives

After today's class, you should be able to:

  • Understand how lists and dictionaries can represent any data kind
  • Explain different nested structures

Lesson Outline

Quiz 5A: 25 minutes

  • Log in as student on the lab machine
  • Open web browser, go to canvas and log in with your eid
  • In canvas, go to Modules, Quiz5A
  • Do part one of the Module
  • The programming portion is given on sheet of paper
  • Open Thonny
  • Submit work using Canvas with Gradesope, Module Quiz5A, Programming

Nested Data

Inclass Activity

Datasets

  • CORGIS
    • Collection of Really Great, Interesting, Situated Datasets
  • Example: County Demographics
  • List comprehensions
    • Example: [x ** 2 for x in range(10)]

CSV Example

import csv
from pprint import pprint

data = []
with open("county_demographics.csv") as file:
    reader = csv.reader(file)
    data = [row for row in reader]

pprint(data[0])

JSON Example

import json
from pprint import pprint

with open("county_demographics.json") as file:
    data = json.load(file)  # dictionary

for item in data:
    if item["County"] == "Harrisonburg city":
        pprint(item)

Your To-Do List

By today

By Thursday

  • Programming Assignment 2: PA 2
    • Part B due Thursday 11pm

Complete by Monday November 13th