Lists + Dictionaries, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Lists + Dictionaries in one minute
What students need to know
& gives items that appear in both sets. 2 and 3 are in both a and b. - is difference — items in the left set but not the right.
^ is symmetric difference — items in either set but not both. Think of | as 'OR' — items in set A OR set B (or both).
Mistakes students make
- Sets don't support + for union. Use | or .union().
- Use & for set intersection, not 'and' (which is a boolean operator).
- Use | for set union, not 'or' (which is a boolean operator).
- Use parentheses () to call methods, not square brackets [].
PREVIOUS · MODULE 42Nested Lists
YOU ARE HERE · MODULE 43Lists + Dictionaries
NEXT · MODULE 44File Operations – Open
What students will learn in this module
Every question in Module 43
Quick questions
- {1,2,3} | {3,4,5} returns?A{3}B{1, 2, 3, 4, 5}
- {1,2,3} & {2,3,4} returns?A{2, 3}B{1, 2, 3, 4}
- {1,2,3} - {2,3,4} returns?A{4}B{1}
- {1,2,3} ^ {2,3,4} returns?A{1, 4}B{2, 3}
- What does | do with sets?AUnion combines all itemsBIntersection
Key terms
Students type the meaning of:
UnionIntersectionDifferenceSymmetric difference
Match the pairs
a = {1,2}
b = [3,4]
a | bMatch it to what it doess = {1,2,3}
s.add([4,5])Match it to what it doesa = {1,2,3}
b = {2,3,4}
a & bMatch it to what it doesa = {1,2,3}
b = {2,3,4}
a - bMatch it to what it doesa={1,2}
b={2,3}
print(a | b)Match it to what it doesa={1,2}
b={2,3}
print(a & b)Match it to what it doesFill in the blanks
a = {1, 2, 3} b = {3, 4} print(a _ b)a = {1, 2, 3} b = {2, 3, 4} print(a _ b)a = {1, 2, 3} b = {2, 3} print(a _ b)a = {1, 2} b = {1, 2, 3} print(a.________(b))a = {1, 2, 3} b = {2, 3, 4} print(a _ b)
Spot the error
Question 1
Aa = {1, 2, 3}Bb = {3, 4}Cprint(a + b)
Question 2
Aa = {1, 2, 3}Bb = {2, 3, 4}Cprint(a and b)
Question 3
Aa = {1, 2, 3}Bb = {2, 3, 4}Cprint(a or b)
Question 4
Aa = {1, 2, 3}Bb = {3, 4}Ccombined = a.union[b]Dprint('Union:', combined)
Question 5
Aprint({1, 2}.subset({1, 2, 3}))Ba = {1, 2}Cb = {1, 2, 3}Dprint('Done')
