Skip to content
Computing · Year 9

Active learning ideas

Dictionaries: Key-Value Pairs

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.

National Curriculum Attainment TargetsKS3: Computing - Programming and DevelopmentKS3: Computing - Data Representation
25–45 minPairs → Whole Class4 activities

Activity 01

Problem-Based Learning35 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.

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

Facilitation TipDuring 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.

What to look forPresent students with a Python code snippet that attempts to access a non-existent key in a dictionary. Ask: 'What error will this code produce, and why? How could you modify the code to handle this situation gracefully?'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 02

Problem-Based Learning45 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.

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

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

What to look forPose the question: 'Imagine you are building a simple inventory system for a small shop. Would you use a list or a dictionary to store the items, and why? Consider how you would add new items, check stock levels, and find a specific product.'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 03

Problem-Based Learning25 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.

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

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

What to look forGive each student a small card. Ask them to write a Python dictionary representing three fruits, with the fruit name as the key and its color as the value. Then, ask them to write one line of code to retrieve the color of 'apple'.

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 04

Problem-Based Learning30 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.

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

What to look forPresent students with a Python code snippet that attempts to access a non-existent key in a dictionary. Ask: 'What error will this code produce, and why? How could you modify the code to handle this situation gracefully?'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

A few notes on teaching this unit

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.

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.


Watch Out for These Misconceptions

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

    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.

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

    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.

  • During 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.

    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.


Methods used in this brief