ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
print(list(dict.fromkeys([3, 1, 3, 2, 1])), sorted(set([3, 1, 3, 2, 1]))[::-1])
  1. A. [1, 2, 3] [3, 2, 1]
  2. B. [3, 1, 2] [1, 2, 3]
  3. C. [3, 1, 2] [3, 2, 1]
  4. D. [3, 1, 2, 3] [3, 2, 1]

Correct answer: C. [3, 1, 2] [3, 2, 1]

dict.fromkeys keeps the first occurrence of each key in order, while sorting the set and reversing it gives descending order.

More Python Programming questions

Exams that ask this topic