ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(len({'a': 1, 'a': 2}), {'a': 1, 'a': 2}, list({1, 2, 1}), sorted({3, 1, 2} & {2, 3, 4}))
  1. A. 2 {'a': 1} [1, 2, 1] [2, 3]
  2. B. 1 {'a': 1} [1, 2] [2, 3]
  3. C. 1 {'a': 2} [1, 2] [2, 3]
  4. D. 1 {'a': 2} [1, 2, 1] [1, 2, 3]

Correct answer: C. 1 {'a': 2} [1, 2] [2, 3]

A repeated dict key keeps one entry, with the last value, so the dict is {'a': 2}. A set drops duplicates, and the intersection of the two sets is 2 and 3.

More Python Programming questions

Exams that ask this topic