## Introduction

Python offers a wide range of built-in modules to make coding easier & more efficient. One such module is the bisect module, which provides a way to efficiently search & insert elements into a sorted list.

In this article, we will talk about the bisect module & learn how to use its functions to perform binary search operations on sorted lists. We will discuss the basics of the bisect module, its significant functions, with examples.

## Understanding the Python bisect module

The bisect module in Python is a useful tool for working with sorted lists. It provides a set of functions that allow you to efficiently search for elements in a sorted list & insert new elements while maintaining the list's sorted order. The module is based on the binary search algorithm, which makes it much faster than linear search, especially for large lists.

The bisect module is part of Python's standard library, so you don't need to install any additional packages to use it. To start using the bisect module, you simply need to import it in your Python script using the following statement:

`import bisect`

With the bisect module imported, you can now use its functions to perform various operations on sorted lists. The module provides six main functions: bisect(), bisect_left(), bisect_right(), insort(), insort_left(), & insort_right().

Letâ€™s discuss these 6 functions in detail :

The bisect module provides several significant functions that allow you to perform binary search operations on sorted lists. Let's take a closer look at each of these functions:

**1. bisect(list, num, lo=0, hi=len(list)):** This function returns the index where the element "num" should be inserted in the sorted list "list" to maintain its sorted order. The optional arguments "lo" & "hi" allow you to specify the range of indices to search within.

**2. bisect_left(list, num, lo=0, hi=len(list)):** This function is similar to bisect(), but it returns the leftmost index where "num" should be inserted if there are duplicate elements in the list.

**3. bisect_right(list, num, lo=0, hi=len(list)): **This function is similar to bisect(), but it returns the rightmost index where "num" should be inserted if there are duplicate elements in the list.

**4. insort(list, num, lo=0, hi=len(list)):** This function inserts the element "num" into the sorted list "list" while maintaining its sorted order. It uses the bisect() function internally to find the appropriate index for insertion.

**5. insort_left(list, num, lo=0, hi=len(list)):** This function is similar to insort(), but it uses bisect_left() internally to find the appropriate index for insertion.

**6. insort_right(list, num, lo=0, hi=len(list)): **This function is similar to insort(), but it uses bisect_right() internally to find the appropriate index for insertion.