← 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))
- A.1 3
- B.1 2
- C.2 3
- 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 →