Skip to content

Dictionaries: Key-Value PairsActivities & Teaching Strategies

Active learning works because students need to experience the difference between list-style indexing and key-based lookup to truly grasp why dictionaries exist in programming. When Year 9 students create real contact books or student records, they encounter errors firsthand and build lasting understanding of how keys enable fast, reliable access.

Year 9Computing4 activities25 min45 min

Learning Objectives

  1. 1Compare the efficiency of data retrieval between Python lists and dictionaries for a dataset of 100 student records.
  2. 2Design a Python program that utilizes a dictionary to store and manage at least five attributes for 10 different contacts.
  3. 3Evaluate three distinct scenarios and justify the selection of a dictionary as the most appropriate data structure for each.
  4. 4Create a Python script that demonstrates adding, accessing, updating, and deleting key-value pairs in a dictionary.

Want a complete lesson plan with these objectives? Generate a Mission

35 min·Pairs

Pair Programming: Contact Book Creator

Pairs start with an empty dictionary and add five contacts as name:phone pairs. They write functions to retrieve, update, and display all entries. Pairs test each other's code and time lookups against a list version.

Prepare & details

Compare the advantages of using a dictionary over a list for storing student records.

Facilitation Tip: During Pair Programming: Contact Book Creator, circulate and watch for students using list-style access like contacts[0] instead of contacts['name'], then prompt them to rewrite with proper keys.

Setup: Groups at tables with access to research materials

Materials: Problem scenario document, KWL chart or inquiry framework, Resource library, Solution presentation template

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
45 min·Small Groups

Small Groups: Student Records Comparison

Groups build identical student data in lists and dictionaries. They perform 10 lookups each way and record times. Groups present findings, explaining when dictionaries outperform lists.

Prepare & details

Design a Python program that uses a dictionary to store contact information.

Facilitation Tip: In Small Groups: Student Records Comparison, provide deliberately duplicated keys so students see new values overwrite old ones and discuss why uniqueness matters for records.

Setup: Groups at tables with access to research materials

Materials: Problem scenario document, KWL chart or inquiry framework, Resource library, Solution presentation template

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
25 min·Whole Class

Whole Class: Scenario Selector

Display three scenarios on the board, like inventory or scores. Class votes on best structure, then codes a quick demo. Discuss results as a group.

Prepare & details

Evaluate scenarios where a dictionary is the most appropriate data structure.

Facilitation Tip: For Whole Class: Scenario Selector, project incorrect dictionary code and ask groups to identify and fix errors before running, reinforcing debugging habits.

Setup: Groups at tables with access to research materials

Materials: Problem scenario document, KWL chart or inquiry framework, Resource library, Solution presentation template

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
30 min·Individual

Individual: Dictionary Fix-Up

Provide buggy dictionary code with errors like invalid keys or missing values. Students debug, add features like search, and run tests. Share one fix with the class.

Prepare & details

Compare the advantages of using a dictionary over a list for storing student records.

Setup: Groups at tables with access to research materials

Materials: Problem scenario document, KWL chart or inquiry framework, Resource library, Solution presentation template

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills

Teaching This Topic

Start with concrete examples students can relate to, like contact books or grade records, to build intuition before abstract syntax. Avoid rushing into code; let students struggle with errors first, then guide them to discover solutions through testing. Research shows hands-on debugging strengthens long-term retention of dictionary behaviors.

What to Expect

Successful learning looks like students confidently creating dictionaries, retrieving values with correct key syntax, and debugging errors such as KeyError or TypeError without teacher prompts. Students should also explain why dictionaries, not lists, are the right choice for managing records in their activities.

These activities are a starting point. A full mission is the experience.

  • Complete facilitation script with teacher dialogue
  • Printable student materials, ready for class
  • Differentiation strategies for every learner
Generate a Mission

Watch Out for These Misconceptions

Common MisconceptionDuring Pair Programming: Contact Book Creator, watch for students treating dictionaries like lists and using index numbers instead of names to access contacts.

What to Teach Instead

Ask students to run their code with an index like contacts[0] and observe the KeyError. Then guide them to rewrite using proper keys such as contacts['name'] and discuss why keys enable reliable access.

Common MisconceptionDuring Small Groups: Student Records Comparison, watch for students assuming each key can hold multiple values if duplicated.

What to Teach Instead

Deliberately include keys like 'grade' with the same value in multiple records and challenge groups to predict the output. After seeing later values overwrite earlier ones, ask them to explain why uniqueness matters for accurate records.

Common MisconceptionDuring Individual: Dictionary Fix-Up, watch for students changing all keys to the same data type, like converting all keys to strings, even when integers are appropriate.

What to Teach Instead

Provide a dictionary with mixed key types, such as {1: 'math', 'name': 'Alice', 2: 'science'}, and ask students to identify and correct any TypeError during testing. Discuss why immutability, not uniformity, matters for keys.

Assessment Ideas

Quick Check

After Pair Programming: Contact Book Creator, present students with a snippet that tries to access a non-existent key using contacts['email'] when only 'phone' exists. Ask: 'What error will this produce, and how could you handle it safely?'

Discussion Prompt

During Whole Class: Scenario Selector, pose the question: 'For a simple inventory system, would you use a list or a dictionary to store items? Discuss how you would add items, check stock, and find a product, then share your reasoning with the class.'

Exit Ticket

After Individual: Dictionary Fix-Up, give each student a card with a small dictionary representing three fruits and colors. Ask them to write one line of code to retrieve the color of 'apple' and explain why keys work for retrieval.

Extensions & Scaffolding

  • Challenge: Ask early finishers to extend their contact book to include nested dictionaries for addresses and phone numbers.
  • Scaffolding: Provide a partially completed dictionary with missing keys and values for students to fill in before retrieving specific entries.
  • Deeper exploration: Introduce dictionary methods like .keys(), .values(), and .items() and ask students to iterate over records to generate reports.

Key Vocabulary

DictionaryA Python data structure that stores data in unordered collections of key-value pairs. Each key must be unique and immutable.
Key-Value PairA fundamental unit within a dictionary, consisting of a unique identifier (the key) and its associated data (the value).
KeyA unique identifier used to access a specific value within a dictionary. Keys are typically strings or numbers.
ValueThe data associated with a specific key in a dictionary. Values can be of any data type, including lists or other dictionaries.
Hash TableThe underlying data structure often used to implement dictionaries, enabling fast lookups, insertions, and deletions based on keys.

Ready to teach Dictionaries: Key-Value Pairs?

Generate a full mission with everything you need

Generate a Mission