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('.')))))- A. ['1.10', '1.10.1', '1.9']
- B. ['1.10.1', '1.9', '1.10']
- C. ['1.9', '1.10.1', '1.10']
- 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
- What is printed? python print(sorted(['1.10', '1.9', '1.10.1']))
- What is printed? python values = [2.0, 2, '2'] print(len(set(values[:2])), len(set(values)), values[0] == values[1] == 2)
- What is printed? python t = 3 print(t // 2 if t % 2 else t / 2, 1 if t else 0, t and 0, t or 0, not t)
- What is printed? python print(int(0.999999999999999999999), round(0.4999999999999999), round(-0.4999999999999999), int(-0.9))
- What is printed? python print(f'{12.0:g}', f'{12.5:g}', f'{0.00001234:g}', f'{123456789:g}', f'{1.5e300:g}')
- What is printed? python print(10 18 10 18 // 10 35, 2 64 // 2 32, 2 64 % 2 32)