ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(max(range(5), key=lambda i: (i % 3, -i)))
- A. 1
- B. 4
- C. 0
- D. 2
Correct answer: D. 2
The key (i % 3, -i) is largest when i % 3 is 2, which happens only at i = 2. The tuple's second item breaks ties in favour of smaller i.
More Python Programming questions
- What is printed? python print(sum(x x for x in range(-3, 4)), sum(abs(x) for x in range(-3, 4)))
- What is printed? python print(2 0.5 2 0.5 == 2, round(2 0.5 2 0.5, 12) == 2)
- What is printed? python print(''.join(reversed('ab' 2)), 'ab'[::-1] 2 == 'baba')
- Which operation is O(1) on average in CPython?
- A loop runs s += c for 100000 single characters in CPython. Which statement is most accurate?
- Which statement about converting a string to an int in Python 3.13 is correct?