Lesson 6.02: Dictionaries Methods
Learning Objectives
Students will be able to...
- Define and identify: pop, default value
- Update values in a dictionary
- Add values to a dictionary
- Remove values from a dictionary
Materials/Preparation
- Do Now
- Lab - Word Counter
- Solution
- Associated Reading - section 5.2 of Book
- Read through the do now, lesson, and lab so that you are familiar with the requirements and can assist students
Pacing Guide
| Duration | Description |
|---|---|
| 5 Minutes | Do Now |
| 10 Minutes | Lesson |
| 35 Minutes | Lab |
| 5 Minutes | Debrief |
Instructor's Notes
- Do Now
- Display the Do Now on the board.
- Students type code that edits dictionaries by modifying, adding, or removing key:value pairs.
- Lesson
- Discuss part 1 of the Do Now.
- Describe that you can update a value in a dictionary in a similar way to how you would update a value in a list.
- Discuss part 2 of the Do Now.
- Note that you can add values to a dictionary by using the same syntax.
- Review: How might you check if a value was in a dictionary before adding it?
- Discuss part 3 of the Do Now
- Review what pop does, as well as what the second argument does.
- The second argument in
popis described as the default value. This is the value that will be returned if the first argument is not in the dictionary.
- The second argument in
- Review what pop does, as well as what the second argument does.
- Discuss part 1 of the Do Now.
- Lab
- Students will create a word count algorithm that will count the number of words in a list of words.
- Debrief
- Talk about any confusion the students had. Discuss additional ideas of how dictionaries might be useful.
Accommodation/Differentiation
Some students may need to be explicitly reminded of the in keyword to check if a certain key is in their dictionary.