ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(sorted({x % 4 for x in range(10)}))
  1. A. [0, 1, 2, 3]
  2. B. [0, 1, 2]
  3. C. [1, 2, 3, 4]
  4. D. [0, 1, 2, 3, 4]

Correct answer: A. [0, 1, 2, 3]

The set comprehension keeps distinct remainders of 0 to 9 modulo 4, which are 0, 1, 2 and 3.

More Python Programming questions

Exams that ask this topic