ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(sorted([0.5, -0.5, 0, True, False], key=abs))
- A. [False, 0, 0.5, -0.5, True]
- B. [0, False, 0.5, -0.5, True]
- C. [0, 0.5, False, -0.5, True]
- D. [0, False, 0.5, True, -0.5]
Correct answer: B. [0, False, 0.5, -0.5, True]
The keys are 0.5, 0.5, 0, 1 and 0, and the stable sort keeps the input order for ties. So 0 comes before False, 0.5 before -0.5, and True last.
More Python Programming questions
- What is printed? python print(str(2100)[:5], len(str(2100)), str(2100).count('0'))
- What is printed? python print(int('9' 5) 2 // 109, (109 - 1) 2 // 109)
- What is printed? python x = 0 for i in range(1, 101): x += i print(x, x // 2 2 == x, x % 2)
- What is printed? python print(','.join(['a', 'b']), ','.join('ab'), '%s' % ['a', 'b'], str(('a',)))
- What is printed? python import math print(math.prod([2, 3, 4]), math.prod([]), math.prod([1.5, 2]), math.prod(range(1, 6)) ==…
- What is printed? python words = ['bb', 'a', 'ccc'] print(max(words), max(words, key=len), min(words, key=len), sorted(words, key=lambda w…