Nested Lists, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Nested Lists in one minute
What students need to know
Sets automatically remove duplicate values — each item appears only once. Use set() for an empty set. .add() inserts one element.
{} creates an empty dict, not a set — you must use set(). Sets have no guaranteed order, so s[0] doesn't work — use in to check membership.
Mistakes students make
- {} creates an empty dict, not a set. Use set() for an empty set.
- Sets use .add(), not .append() (that's for lists).
- Sets are unordered: you can't access items by index.
- 5 is not in the set: remove() raises KeyError. Use discard() instead.
PREVIOUS · MODULE 41Sets – Operations
YOU ARE HERE · MODULE 42Nested Lists
NEXT · MODULE 43Lists + Dictionaries
What students will learn in this module
Every question in Module 42
Quick questions
- What makes a set special?AItems are orderedBItems are unique no duplicates
- How do you create an empty set?Aset()B{}
- {1, 2, 2, 3} becomes?A{1, 2, 3}B{1, 2, 2, 3}
- Can you access set items by index?AYes like listsBNo sets are unordered
- How do you add to a set?A.add()B.append()
Key terms
Students type the meaning of:
Setset().add(item).remove(item)
Match the pairs
s = {1, 2, 3}
print(s[0])Match it to what it doesempty = {}Match it to what it doess = {1, 2, 2, 3}Match it to what it doess = set() s.add(5)Match it to what it does
s = {3, 1, 2, 1}
print(len(s))Match it to what it doess = {1, 2, 3}
print(2 in s)Match it to what it doesFill in the blanks
s = ___()
s = {1, 2, 3} s.___(4)s = {1, 2, 3} s._______(2)print(3 __ {1, 2, 3})s = {1, 2, 2, 3} print(___(s))
Spot the error
Question 1
A# Create an empty setBs = {}Cs.add(1)Dprint('Set:', s)
Question 2
As = {1, 2, 3}Bs.append(4)Cprint('Set:', s)Dprint('Done')
Question 3
As = {1, 2, 3}Bfirst = s[0]Cprint('First:', first)Dprint('Done')
Question 4
As = {1, 2, 3}Bs.remove(5)Cprint('Set:', s)Dprint('Done')
Question 5
As = {[1, 2], [3, 4]}Blabel = 'Coords'Cprint('Set:', s)Dprint('Done')
