🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Sorting, heapq and bisect: all 10 questions

Quiz: Sorting, heapq and bisect · Question 8 of 10

What does this print? (code)

What does this print?

from bisect import bisect_left, bisect_right
a = [10, 20, 20, 30]
print(bisect_left(a, 20), bisect_right(a, 20))
  1. A.1 3
  2. B.1 2
  3. C.2 3
  4. D.0 4
Answer & explanation

Correct answer: 1 3

bisect_left stops before the equal items (index 1); bisect_right stops after them (index 3).

Can you get the rest right without peeking?

Take the timed Quiz: Sorting, heapq and bisect quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →