Editor

Sets: What Does This Print

What does this print? · Intermediate · about 8 min

Read each short program and type exactly what it prints, with each printed line on its own line. If a program stops with an error, type the error's name, like TypeError.

Example

print(3 in {1, 2, 3})

prints

True
  1. Program 1

    s = {3, 1, 3, 2, 1}
    print(len(s))
  2. Program 2

    s = {1, 2, 3}
    s.add(2)
    s.add(4)
    print(sorted(s))
  3. Program 3

    a = {1, 2, 3}
    b = {2, 3, 4}
    print(sorted(a & b), sorted(a | b))
  4. Program 4

    a = {1, 2, 3}
    b = {2, 3, 4}
    print(sorted(a - b), sorted(b - a))
  5. Program 5

    s = {}
    print(type(s))
  6. Program 6

    s = {1, 2}
    s.discard(5)
    s.remove(5)
    print(len(s))
  7. Program 7

    print({1, 2} <= {1, 2, 3}, {1, 2} == {2, 1})
  8. Program 8

    s = set("hello")
    print(len(s), "l" in s)