Nested Lists, online

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

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.

Discover other journeys with this module

What students will learn in this module

Every question in Module 42

Quick questions

  1. What makes a set special?AItems are orderedBItems are unique no duplicates
  2. How do you create an empty set?Aset()B{}
  3. {1, 2, 2, 3} becomes?A{1, 2, 3}B{1, 2, 2, 3}
  4. Can you access set items by index?AYes like listsBNo sets are unordered
  5. How do you add to a set?A.add()B.append()

Key terms

Students type the meaning of:

  • Set
  • set()
  • .add(item)
  • .remove(item)

Match the pairs

s = {1, 2, 3}
print(s[0])
Match it to what it does
empty = {}Match it to what it does
s = {1, 2, 2, 3}Match it to what it does
s = set()
s.add(5)
Match it to what it does
s = {3, 1, 2, 1}
print(len(s))
Match it to what it does
s = {1, 2, 3}
print(2 in s)
Match it to what it does

Fill in the blanks

  1. s = ___()
  2. s = {1, 2, 3}
    s.___(4)
  3. s = {1, 2, 3}
    s._______(2)
  4. print(3 __ {1, 2, 3})
  5. 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')