ProgrammingModerateProduct-company MCQ pattern

What is printed?

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

Correct answer: C. {0: 6, 1: 4, 2: 5}

Keys repeat (x % 3 takes only the values 0, 1, 2), and each later x overwrites the earlier value for that key. The last x for key 0 is 6, for key 1 it is 4, and for key 2 it is 5. Insertion order follows the first time each key appeared.

More Python Programming questions

Exams that ask this topic