ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print(len({1: 'a', True: 'b', 1.0: 'c'}), list({True: 1, 1: 2}.keys()))
  1. A. 1 [1]
  2. B. 2 [True, 1]
  3. C. 1 [True]
  4. D. 3 [1, True, 1.0]

Correct answer: C. 1 [True]

1, True and 1.0 hash and compare equal, so each dict literal has one key. The dict keeps the first key object it saw, which is True in the second dict.

More Python Programming questions

Exams that ask this topic