ProgrammingHardProduct-company MCQ pattern
What is printed on the first line?
What is printed on the first line?
data = [('x', 3.0), ('y', 3), ('z', 2.5)]
print(sorted(data, key=lambda t: t[1]))
print(max(data, key=lambda t: t[1]), min(data, key=lambda t: t[1])[0])- A. [('z', 2.5), ('y', 3), ('x', 3.0)]
- B. [('z', 2.5), ('x', 3.0), ('y', 3)]
- C. [('x', 3.0), ('y', 3), ('z', 2.5)]
- D. [('z', 2.5), ('x', 3), ('y', 3.0)]
Correct answer: B. [('z', 2.5), ('x', 3.0), ('y', 3)]
3.0 and 3 compare equal, and the stable sort keeps 'x' ahead of 'y'. The smallest value is 2.5, so the first line starts with z.
More Python Programming questions
- What is printed? python s = 'level' t = ''.join(reversed(s)) print(s == t, s[::-1] is s, s[::-1] == t, s.count('l') s.count('e'))
- What is printed? python a = 1e308 b = a 10 print(b, -b, b - b if False else 0, b > a, b == float('inf'))
- What is printed? python import math print(math.sqrt(16), math.sqrt(2) 2 == 2, math.isqrt(2) 2 == 2, math.pow(2, 0.5) == 2 0.5)
- What is printed? python print(int(0.1 10) == 1, int(0.7 10), int(4.35 100), round(4.35 100))
- What is printed? python print(len(str(264)), 264 // 1019, 264 % 1019, len(str(264 - 1)))
- What is printed? python print(-7 // 2 2 + -7 % 2 == -7, 7 // -2 -2 + 7 % -2 == 7, -(-7 // 2))