ProgrammingModerateProduct-company MCQ pattern

What is printed?

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

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

key=abs sorts by absolute value (5, 3, 2, 1 in descending order) but keeps the original elements, so the signs stay: [-5, 3, 2, -1].

More Python Programming questions

Exams that ask this topic