Useful Python Libraries & Modules
Bisect
Incredible module for inserting and searching an array for values using a binary search
- Useful methods include:
bisect.bisect(arr, val)
- searches for the value in the array and returns an insertion point coming after any existing entries of the valuebisect.bisect_left
- searches for the value of the array and returns insertion point to the left of itbisect.bisect_right
- same asbisect_left
but for insertions to the rightbisect.insort
- inserts a value into the array in a sorted manner. Usesbisect_right
andinsert
to insert the value. This is time complexity $O(N)$ for a list- If you intend to do this, a better approach could be to use a different data structure than a list