Nov 08: Quiz 5a, Lists of Lists
Learning Objectives
After today's class, you should be able to:
- Describe how any kind of data can be represented with lists and dictionaries.
Announcements¶
- Chapter 11: Nested Data
- Project 2 (due Nov 14)
- Part B due Thursday, Nov 9th
- Part C due Tuesday, Nov 14th
Haiku Debrief¶
- haiku_checker.py
- Work on projects in VS Code
- Note: Use Thonny on quizzes
Quiz 5a¶
- Log in as
student
- Only two windows:
- Thonny
- Web browser
- Web traffic monitored
- Log out when finished
Ch11 Preview¶
- CORGIS
- Collection of Really Great, Interesting, Situated Datasets
- Example: County Demographics
- CSV format (nested lists)
- JSON format (nested dictionaries)
- List comprehensions!
- Ex:
[x ** 2 for x in range(10)]
- Ex:
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)
for item in data:
if item["County"] == "Harrisonburg city":
pprint(item)