SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 6 · 6.3b

Tuples &
Dictionaries

Immutable Tuples · key:value Pairs · Iterating Dictionaries

CSZoneEdexcel GCSE Computer Science 1CP2
Tuples

Immutable Ordered Collections

coordinates = (51.5, -0.12) # tuple (fixed)
point = (3, 4)

print(coordinates[0]) # 51.5
print(len(point)) # 2

# Unpack a tuple
x, y = point
print(x, y) # 3 4
Tuples use parentheses (); lists use square brackets []
Tuples are immutable — you cannot add, remove, or change elements after creation
Use tuples for data that should not change — coordinates, RGB values, database rows
Dictionaries

Key-Value Pairs

student = {
"name": "Alice",
"age": 16,
"grade": "A"
}

print(student["name"]) # Alice
student["age"] = 17 # update value
student["email"] = "a@b" # add new key
Dictionaries store data as key: value pairs — access by key, not index
Keys must be unique and immutable (strings or numbers); values can be anything
Use .get(key) to safely retrieve — returns None if key doesn't exist (no error)
Iterating Dictionaries

Looping Through Keys and Values

scores = {"Alice": 85, "Bob": 72, "Charlie": 91}

for name in scores: # iterate keys
print(name, scores[name])

for name, score in scores.items(): # key+value
if score >= 80:
print(name, "passed")

print(scores.keys()) # all keys
print(scores.values()) # all values
.items(): returns key-value pairs as tuples — most common way to loop
del scores["Bob"]: removes a key-value pair
Exam Practice

Have a go at this question

Edexcel-style question
State one difference between a list and a tuple in Python.
2 marks
A list is mutable [1] — you can add, remove and change elements. A tuple is immutable [1] — its contents cannot be changed after creation.
Key Takeaways

What to Remember

Tuple: ordered, immutable, uses () — for fixed data like coordinates
Dictionary: key-value pairs, unordered (Python 3.7+ insertion-ordered), mutable
Access dict: d["key"]; update: d["key"]=val; iterate: for k, v in d.items()
Use .get(key) to avoid KeyError when key might not exist