ProgrammingModerateWipro NLTH · Python

What is printed?

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

Correct answer: B. {0, 1, 2} {0: 0, 1: 1, 2: 4}

x % 3 takes only the values 0, 1, 2 and sets drop duplicates; the dict comprehension maps x to x*x for x in 0..2.

More Python Programming questions

Exams that ask this topic