ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(sorted([10, 2, 33], key=str), sorted(['10', '2', '33'], key=int))
  1. A. [10, 2, 33] ['10', '2', '33']
  2. B. [10, 2, 33] ['2', '10', '33']
  3. C. [10, 33, 2] ['2', '10', '33']
  4. D. [2, 10, 33] ['2', '10', '33']

Correct answer: B. [10, 2, 33] ['2', '10', '33']

key=str compares the numbers as text, so '10' < '2' < '33' and the original ints keep their order by this key. key=int converts the strings to numbers, so the second list is numerically sorted.

More Python Programming questions

Exams that ask this topic