Question 3
Back to Exercise
What is the output of the following Python program?
import bisect
a = [10, 20, 20, 30]
print(bisect.bisect_left(a, 20), bisect.bisect_right(a, 20), bisect.bisect_left(a, 25), bisect.bisect_left(a, 5))
- A 1 2 3 0
- B 2 3 3 0
- C 1 3 3 0 Correct
- D 1 3 2 -1
Correct Answer: Option C
bisect_left returns the first position where 20 could go (before the equal items), bisect_right the position after them; 25 would be inserted at index 3.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!