Lists + Dictionaries, online

Six activities your students do on their own devices. See who's finished, and their scores.

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 [].

Discover other journeys with this module

What students will learn in this module

Every question in Module 43

Quick questions

  1. {1,2,3} | {3,4,5} returns?A{3}B{1, 2, 3, 4, 5}
  2. {1,2,3} & {2,3,4} returns?A{2, 3}B{1, 2, 3, 4}
  3. {1,2,3} - {2,3,4} returns?A{4}B{1}
  4. {1,2,3} ^ {2,3,4} returns?A{1, 4}B{2, 3}
  5. What does | do with sets?AUnion combines all itemsBIntersection

Key terms

Students type the meaning of:

  • Union
  • Intersection
  • Difference
  • Symmetric difference

Match the pairs

a = {1,2}
b = [3,4]
a | b
Match it to what it does
s = {1,2,3}
s.add([4,5])
Match it to what it does
a = {1,2,3}
b = {2,3,4}
a & b
Match it to what it does
a = {1,2,3}
b = {2,3,4}
a - b
Match it to what it does
a={1,2}
b={2,3}
print(a | b)
Match it to what it does
a={1,2}
b={2,3}
print(a & b)
Match it to what it does

Fill in the blanks

  1. a = {1, 2, 3}
    b = {3, 4}
    print(a _ b)
  2. a = {1, 2, 3}
    b = {2, 3, 4}
    print(a _ b)
  3. a = {1, 2, 3}
    b = {2, 3}
    print(a _ b)
  4. a = {1, 2}
    b = {1, 2, 3}
    print(a.________(b))
  5. 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')