Challenge 1
Find the insertion point before an equal value or where the target would fit.
from bisect import bisect_left
values = [10, 20, 30, 40]
target = 25
position =
print(position)
Press Ctrl⌘Enter to check your answer
Practise finding left and right insertion points, inserting while preserving order, and maintaining a list of records by key.
Challenge 1
from bisect import bisect_left
values = [10, 20, 30, 40]
target = 25
position =
print(position)
Press Ctrl⌘Enter to check your answer
Challenge 2
from bisect import bisect_right
values = [2, 4, 4, 4, 9]
position =
print(position)
Press Ctrl⌘Enter to check your answer
Challenge 3
from bisect import insort
scores = [10, 20, 30, 40]
print(scores)
Press Ctrl⌘Enter to check your answer
Challenge 4
from bisect import insort
records = [{"score": 10, "name": "Ada"}, {"score": 30, "name": "Lin"}]
new_record = {"score": 20, "name": "Sam"}
print([(record["score"], record["name"]) for record in records])
Press Ctrl⌘Enter to check your answer