ProgrammingModerateTCS NQT · Accenture

What is printed?

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

Correct answer: B. [1, 3] [3, 1]

Iterating a dict gives its keys, so sorted returns the keys 1 and 3. reversed then flips that list, which gives 3, 1.

More Python Programming questions

Exams that ask this topic