ProgrammingEasyInfosys pattern

What is printed?

What is printed?
data = [1, 2, 2, 3, 3, 3]
print({x for x in data if x > 1})
  1. A. {2, 2, 3, 3, 3}
  2. B. {1, 2, 3}
  3. C. {2, 3}
  4. D. {3}

Correct answer: C. {2, 3}

A set comprehension discards duplicates automatically, and the filter keeps only values greater than 1, so the distinct surviving values are 2 and 3.

More Python Programming questions

Exams that ask this topic