ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import bisect
print(bisect.bisect_left([5, 4, 3], 4))
  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 0

Correct answer: D. 0

bisect assumes ascending order. On the descending list [5, 4, 3] the probes see 4 < 4 as False and move the upper bound left, so it returns 0 instead of the answer a sorted list would give.

More Python Programming questions

Exams that ask this topic