From the course: Python Standard Library Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Array bisection

Array bisection - Python Tutorial

From the course: Python Standard Library Essential Training

Start my 1-month free trial

Array bisection

- [Instructor] When you're working with arrays of data that are already sorted, it's sometimes really useful to be able to insert data into a list while maintaining the existing sort order, so that you don't need to sort the list again after each insertion. And this is where Python's array bisection module can help out. So, here in VS code, I'll open up bisect_start and you can see I've imported the bisect module at the top of the file. So, let's imagine we have an array of data that is already sorted, like this one. And let's further suppose that we want to find the location in this array where a new data item would be inserted to maintain the order. The bisect module gives us several methods to perform this operation. The bisect, bisect right, and bisect left functions will quickly determine the index at which a given value should be inserted to maintain order. Bisect and bisect right are essentially synonyms for each other and they will return the index to the right side of an…

Contents