Teacher Curriculum Map · Student Lesson 6.01 · Original slides
Historical TEALS lesson. Review outdated tools and external links before teaching.
Lesson 6.01: Introduction to Dictionaries
Learning Objectives
Students will be able to…
- Define and identify: dictionary, key, value
- Create dictionaries of key-value pairs
- Access items from dictionaries
Materials/Preparation
- Do Now
- Lab - Dictionary of Internet Abbreviations (printable lab document) (editable lab document)
- Associated Reading - section 6.1
- 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
1. Do Now
- Display the Do Now on the board.
- Students will copy and edit code involving creating a dictionary and accessing items from that dictionary.
2. Lesson
Instruction - Dictionaries
- Ask the students what type they think
my_dictionaryis. my_dictionaryis a dictionary or a collection of key-value pairs.- You use the key to look up the value in the dictionary.
- Keys and values can be of any type. The syntax is:
{key : value, key : value, ...}
Discussion
- Did anyone run the
type()function to find out what type ‘my_dictionary’ is? - Ask: what are the keys in the example from the Do Now? What are the associated values?
- Ask the students what
my_dictionary['dog']did, and if this syntax reminds them of anything (lists!).
Instruction - Square Brackets
- To get the value associated with a key in a dictionary you use square brackets.
- You can also use
my_dictionary.get(), which will returnNoneif the key isn’t there. - Note: You can pass in a second argument to
getwhich takes the place of theNonedefault.
More Discussion
- Ask how students would get the value for
chairorcar. - Discuss what happened when students ran
my_dictionary['kittens']?
‘in’ keyword
- Explain that this error is common and means that there is no value in the dictionary. To avoid this error, use the
inkeyword with anifstatement. If a certain key isina specified dictionary, it will returntrue. Otherwise it will returnfalse.
Example
my_dictionary = {'a': 1, 'b': 2, 'c': 3}
if 'a' in my_dictionary:
print("It's there!")
else:
print("It's missing!")
3. Lab
- Students will create a dictionary translating common internet phrases into their meanings.
4. Debrief
- Review what was covered in today’s lesson and check for understanding of the three concepts covered: dictionaries, keys, and values.
Accommodation/Differentiation
- If any students are struggling with today’s lesson, be prepared to offer additional examples of the usefulness of having key-value pairs.
- Students that are moving quickly through the lab should work on the bonus and research how to add new key/value pairs to a dictionary.
Forum discussion
Lesson 6.01: Introduction to Dictionaries (TEALS Discourse Account Required)