ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import bisect
print(bisect.bisect_left([(1, 'a'), (3, 'b'), (5, 'c')], 3, key=lambda t: t[0]))
  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 3

Correct answer: A. 1

Since Python 3.10 bisect takes key=. The key is applied to list elements only, not to x, so you compare 3 with the keys 1, 3, 5. The first position where 3 fits is index 1.

More Python Programming questions

Exams that ask this topic