🔒

Unlock Pro

Subscribe to access all 59 Edexcel 1CP2 lessons.

£7.99/month
or £59/year
🐍 Paper 2 · Topic 6: Programming
6.3b Tuples & Dictionaries
Edexcel 1CP2 · GCSE Computer Science · ~11 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

Tuples

A tuple is an ordered, immutable (unchangeable) collection of items. Once created, items cannot be added, removed, or changed. Defined with parentheses ().

# Creating tuples coordinates = (51.5, -0.12) # latitude, longitude rgb = (255, 128, 0) # colour values days = ("Mon", "Tue", "Wed") # Accessing (same as lists) print(coordinates[0]) # 51.5 print(rgb[-1]) # 0 # Cannot modify a tuple # rgb[0] = 200 → TypeError: tuple does not support item assignment

When to use tuples vs lists: Use a tuple when the data should NOT change (fixed set of values like days of the week, coordinates, or configuration values). Use a list when the data needs to be modified.

FeatureListTuple
Syntax[1, 2, 3](1, 2, 3)
Mutable?Yes — can changeNo — fixed
Ordered?YesYes
Indexinglst[0]tpl[0]
Use caseData that changesFixed/constant data

Dictionaries

A dictionary stores data as key-value pairs. Each key is unique. Access values by key, not by index. Defined with curly braces {}.

# Creating a dictionary student = { "name": "Alice", "age": 16, "grade": "A" } # Accessing values print(student["name"]) # "Alice" print(student["age"]) # 16

Dictionary Operations

person = {"name": "Bob", "age": 20} # Adding/updating person["email"] = "bob@email.com" # add new key person["age"] = 21 # update existing # Removing del person["email"] # delete a key # Checking membership if "name" in person: print("Has name!") # True # .get() — safe access (returns None if key missing) print(person.get("phone", "N/A")) # "N/A" — no error

Iterating Over Dictionaries

scores = {"Maths": 85, "English": 72, "Science": 91} for subject in scores: # iterates over KEYS print(subject, scores[subject]) for key, value in scores.items(): print(key, "→", value) print(list(scores.keys())) # ['Maths', 'English', 'Science'] print(list(scores.values())) # [85, 72, 91]
Exam tip: Dictionaries are excellent for storing structured records (like a student profile with name, age, grade). Edexcel may ask you to access, update or iterate over dictionaries. Remember: keys are unique strings (or numbers), values can be any type.
⚠️ Common Mistakes
  • Trying to modify a tuple — will cause a TypeError (use a list if data needs to change)
  • Using an index to access a dictionary — dict[0] means key 0, NOT the first item
  • Duplicate keys in a dictionary — the second definition overwrites the first silently
  • KeyError when accessing a missing key — use .get() for safe access
  • Confusing tuples (parentheses) with lists (square brackets) in syntax
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — 6.3b Tuples & Dictionaries

8 Edexcel-style questions · instantly marked

Q1What is the key difference between a tuple and a list in Python?[2]
✅ Mark scheme
A tuple is immutable (cannot be changed after creation) [1]; a list is mutable (items can be added, removed, or changed) [1]. Both are ordered and support indexing.
Q2Given: student = {"name": "Alice", "age": 16, "grade": "A"}. Write the code to: (a) print the student's name (b) update the age to 17 (c) add a new key "school" with value "Oak Academy".[3]
✅ Mark scheme
(a) print(student["name"]) [1]; (b) student["age"] = 17 [1]; (c) student["school"] = "Oak Academy" [1]. Note: accessing a dictionary value uses the KEY in square brackets, not an index number.
Q3Write Python code to create a dictionary called 'capitals' with at least 3 country-capital pairs, then print the capital of one country using its key.[3]
✅ Mark scheme
capitals = {"UK": "London", "France": "Paris", "Germany": "Berlin"} (or any valid countries) [2 — 1 for structure, 1 for at least 3 pairs]; print(capitals["UK"]) or similar [1]. Keys must be unique.
Q4Give ONE real-world example where a tuple would be more appropriate than a list. Explain why.[2]
✅ Mark scheme
Example: storing GPS coordinates (latitude, longitude) [1]; because coordinates should not change once set — immutability prevents accidental modification, and the data is inherently fixed (accept: RGB colour values, days of the week, date of birth — any appropriate fixed data) [1].
Q5Write a for loop to print every key and value from the dictionary: prices = {"apple": 0.50, "banana": 0.30, "cherry": 1.20}.[3]
✅ Mark scheme
for fruit, price in prices.items(): [2 — 1 for .items(), 1 for two variables]; print(fruit, price) [1]. Accept: for fruit in prices: print(fruit, prices[fruit]) — alternative correct approach [3 marks].
Q6What is the output of: t = (10, 20, 30, 40); print(t[2]); print(len(t))?[2]
✅ Mark scheme
30 [1] — t[2] is index 2 = third item = 30 (indices: 0→10, 1→20, 2→30, 3→40); 4 [1] — len() of a 4-item tuple = 4. Tuples support indexing and len() just like lists.
Q7Explain what happens when you try to run: my_tuple = (1, 2, 3); my_tuple[0] = 10. Why does this happen?[2]
✅ Mark scheme
A TypeError is raised [1]; because tuples are immutable — once created, their elements cannot be changed, added to, or removed [1]. If you need to modify data, use a list instead.
Q8A student record system stores: name, student ID, and subjects (a list). Write Python code to create a dictionary for one student and show how to add a new subject to their subjects list.[4]
✅ Mark scheme
student = {"name": "Alice", "id": "S001", "subjects": ["Maths", "Science"]} [2 — 1 for structure, 1 for subjects as a list]; student["subjects"].append("English") [2 — 1 for accessing the key correctly, 1 for .append()]. Demonstrates a list nested inside a dictionary.
Topic Quiz
Q 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Tuples & Dictionaries

Timed exam-style test — 10 minutes.

← 6.3a ListsTopic 6 · PythonNext: 6.3c File Handling →