← Python

Sets – Operations

Sets support mathematical operations: union |, intersection &, difference -, and subset tests

What it does: people[0] gets the first dict, then ['name'] gets its name value. d['nums'] returns the list, then .append() adds to it. Think of it as a table — each dict is a row with named columns. Lists hold multiple records; dicts give each record named fields. .add() is for sets; lists use .append() to add items. Dict values can be any Python object — strings, numbers, lists, even other dicts. d['tags'] is the list ['python', 'code'] — len() of that list is 2. The value is a list, so use an integer index: d['tags'][0], not d['tags']['a'].

Common mistakes: people is a list: must index first: people[0]['name']. Dicts use keys not indices. Use ['name'] not [0].

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What is a list of dictionaries?
A list where each item is a dictionaryA dictionary of lists
Matches
❌ people = [{'name':'Ali'}] print(people['name'])
Error: people is a list, use [0]
Applying
Meanings
Term
List of dicts
Meaning
A list where each element is a dictionary like records.
Practice
people = [{'name': 'Alice'}, {'name': 'Bob'}]
Testing
Gaps
print(people[]['name'])
Check Answer
Spots
1people = [{'name': 'Alice'}]
2greeting = people['name']

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Walrus' badge — Method Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What is a list of dictionaries?
A. A list where each item is a dictionary ✓
B. A dictionary of lists
Think of it as a table — each dict is a row with named columns
2. people = [{'name':'Al'}]\npeople[0]['name'] returns?
A. {'name':'Al'}
B. 'Al' ✓
people[0] gets the first dict, then ['name'] looks up the key in it
3. d = {'items': [1,2,3]}\nd['items'][0] returns?
A. 1 ✓
B. [1, 2, 3]
d['items'] gets the list, then [0] picks the first element of that list
4. Why combine lists and dicts?
A. For faster code
B. To store structured records ✓
Lists hold multiple records; dicts give each record named fields
5. How do you add a dict to a list of dicts?
A. .append({'key': 'val'}) ✓
B. .add({'key': 'val'})
.add() is for sets; lists use .append() to add items

Match the Pairs

people = [{'name':'Ali'}] print(people['name']) Error: people is a list, use [0]
d = {'tags': ['a','b']} print(d['tags']['a']) Error: Use integer index for list
people = [{'name':'Ali'},{'name':'Bo'}] people[0]['name'] Valid: Returns 'Ali'
d = {'nums': [1,2,3]} d['nums'].append(4) Ok: Append to list inside dict
p = [{'n':'Ali'},{'n':'Bo'}] for x in p: print(x['n']) Output: Ali Bo
d = {'c':['r','g']} print(d['c'][1]) Output: g

Key Term

List of dicts
A list where each element is a dictionary like records.~~list[i]['key']

Fill in the Blanks

1. people = [{'name': 'Alice'}] print(people[0]['name'])
2. d = {'items': [1, 2, 3]} print(d['items'][0])
3. people = [] people.append( {'name': 'Bob'} )
4. for person in people: print(person['name'])
5. student = {'scores': [90, 85]} student['scores'].append(95)

Spot the Error

Question 1
A people = [{'name': 'Alice'}]
B greeting = people['name']
C print('Hello,', greeting)
D print('Done')
Line B — people is a list: must index first: people[0]['name']
Question 2
A people = [{'name': 'Alice'}]
B greeting = people[0][0]
C print('Hello,', greeting)
D print('Done')
Line B — Dicts use keys not indices. Use ['name'] not [0].
Question 3
A d = {'items': [1, 2]}
B d['items'].add(3)
C print('Items:', d['items'])
D print('Done')
Line B — Lists use .append(), not .add() (that's for sets)
Question 4
A people = {'name': 'Alice'}, {'name': 'Bob'}
B first = people[0]['name']
C print('First:', first)
D print('Count:', len(people))
Line A — Missing square brackets: this creates a tuple, not a list
Question 5
A d = {'scores': [90, 85]}
B print(d.scores[0])
Line B — Use bracket notation d['scores'], not dot notation d.scores
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?