Defining Pairs

Jed Rembold

March 30, 2026

Welcome Back!

Quick Announcements

  • ImageShop is due tonight!
    • I have a small window from 2-2:40 today for last day questions
  • I’m still working on PSet 4 and PSet 5 feedback, but it will be done by end of Wednesday

Daily LO’s

  • How to define a dictionary in Python
  • How to utilize common dictionary operations and methods
  • Reading in and parsing data from a file

Group Problems

Problem 1: Tracing Definitions

What is the printed value of the below code?

A = [
    {'name': 'Jill',  'weight':125, 'height':62},
    {'name': 'Sam',   'height':68},
    {'name': 'Bobby', 'height':72},
]
A.append({'weight':204, 'height':70, 'name':'Jim'})
B= A[1]
B['weight'] = 167
print([d['weight'] for d in A if 'weight' in d])
  1. [100,204]
  2. [156,173,204]
  1. [100,167,173,204]
  2. [125,167,204]

Problem 2a: Parsing Pairs

  • This is a coding problem. Work in pairs or trios on a single computer, and discuss your algorithm BEFORE YOU WRITE ANY CODE.
  • The file grades.txt has student names (first and last), then a comma, and then their current grade in a class
  • Your task is to write a function to read in the data from the file and populate a dictionary with the names being the keys and the grades the corresponding values.

Problem 2b: Grade Lookup

  • Swap who is typing!
  • Write a function called get_student_grade which prompts the user for a student’s name and then prints out that student’s grade.
  • If the typed student does not exist, just print out “Student does not exist”

Problem 2c: Grade Reporting

  • Swap who is typing!
  • Write another function get_students_with_grade which prompts the user to type in a desired grade.
  • Then all the names of students who received that grade should be printed to the screen
  • Bonus: Also return all the names as elements of a list

#Demo

The Objective

  • Tweets.csv contains tweet data from users
  • Our task is to see what hashtags are trending or most popular
// reveal.js plugins // Font Awesome Characters