ProgrammingVery hardCodeforces-style · placement coding round

What is printed?

What is printed?
import bisect
a = [9, 7, 5, 3, 1]
print(bisect.bisect_left(a, -6, key=lambda v: -v), bisect.bisect_left(a, 6, key=lambda v: -v))
  1. A. 2 5
  2. B. 3 2
  3. C. 2 3
  4. D. 5 2

Correct answer: A. 2 5

The key function is applied to the list items only, not to x, so the target must be in key space. bisect_left(a, -6) gives index 2, while passing 6 compares it with the negated keys and gives 5.

More Python Programming questions

Exams that ask this topic