bisect
Stdlib — DataPython 2.0+Intermediate
Binary search and sorted-list insertion functions
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
- Dependencies
- None — Python Standard Library
- Install
Included with Python
Learn by Difficulty
Quick Example
python
import bisect # Maintain sorted list sorted_list = [1, 3, 5, 7, 9] bisect.insort(sorted_list, 4) bisect.insort(sorted_list, 6) print(sorted_list) # Find insertion point print(bisect.bisect_left(sorted_list, 5))
The bisect module is part of Python's standard library. Binary search and sorted-list insertion functions.
Try in PlaygroundTags
stdlibdata-structure