ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: D. 3

bisect (same as bisect_right) returns the insertion point after all entries equal to 2, which is index 3. Use bisect_left to get index 1 instead.

More Python Programming questions

Exams that ask this topic