ProgrammingHardTCS CodeVita · GATE CS · Advanced

What does the following Python 3 code print? s = set([1, 2, 2, 3, 3, 3]) print(sorted(s), len(s))

  1. A. [1, 2, 2, 3, 3, 3] 6
  2. B. [1, 1, 2, 2, 3, 3] 3
  3. C. [1, 2, 3] 6
  4. D. [1, 2, 3] 3

Correct answer: D. [1, 2, 3] 3

A set automatically discards duplicates, keeping only the distinct values 1, 2, 3.

More Python Programming questions

Exams that ask this topic