ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import bisect
vals = [10, 20, 30]
print(bisect.bisect_left(vals, 0), bisect.bisect_left(vals, 35), bisect.bisect_left(vals, 20))
  1. A. 1 3 1
  2. B. 0 2 1
  3. C. 0 3 2
  4. D. 0 3 1

Correct answer: D. 0 3 1

A value below every element goes to index 0 and a value above all elements goes to len(vals), which is 3. bisect_left places 20 at index 1, before the existing 20.

More Python Programming questions

Exams that ask this topic