bisect
Binary search and sorted insertion on sorted lists.
Easy
import bisect
e12 = [10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82]
e12[bisect.bisect_left(e12, 50)] # 56 — next standard value
bisect.insort(sorted_list, 25)
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.