ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1])
  1. A. False [2, 1, 3]
  2. B. True [2, 1, 3]
  3. C. True [3, 1, 2]
  4. D. True [1, 2, 3]

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

sorted with reverse=True gives 3, 2, 1, which equals the list [3, 2, 1]. The reversed slice of [3, 1, 2] is [2, 1, 3].

More Python Programming questions

Exams that ask this topic