ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
print(sorted(['1.10', '1.9', '1.10.1'], key=lambda v: tuple(map(int, v.split('.')))))
  1. A. ['1.10', '1.10.1', '1.9']
  2. B. ['1.10.1', '1.9', '1.10']
  3. C. ['1.9', '1.10.1', '1.10']
  4. D. ['1.9', '1.10', '1.10.1']

Correct answer: D. ['1.9', '1.10', '1.10.1']

The tuple key compares version parts as numbers, so (1, 9) comes before (1, 10). The tuple (1, 10, 1) is longer and sorts after (1, 10).

More Python Programming questions

Exams that ask this topic