ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import bisect
print(bisect.bisect_left(range(100), True, key=lambda x: x * x >= 50))
  1. A. 9
  2. B. 8
  3. C. 7
  4. D. 50

Correct answer: B. 8

bisect_left with key finds the first index whose key is at least True. The key x*x >= 50 first becomes True at x = 8, since 7*7 = 49 and 8*8 = 64.

More Python Programming questions

Exams that ask this topic