Bisect: Data Structure in python

Aliya Siddiki
AI Perceptron
Published in
2 min readDec 4, 2020

Bisect: maintain Lists in Sorted Order

The bisect works to finding position for inserting elements into a list and try to sort a list as per the sequence of list in sorted order.

In this it can find the number and divide the list and try to insert the operation only where the number and operation required.

1.bisect(list, num, beg, end)

This function returns the number in the sorted list, where the number passed in argument can be placed so as to maintain the resultant list in sorted order.

it can take the value by default.

one more example to understand here the element which is not present in the list is can suggest you the place where it can be perfect.

2.bisect_left(list, num, beg, end)

This function returns the position in the sorted list, where the number passed in argument can be placed so as to maintain the final list in sorted order.

If the element is already present in the list, the leftmost position where element has to be inserted is returned.

This function takes 4 arguments, list which has to be worked with, number to insert, starting position in list to consider, ending position which has to be considered.

3.bisect_right(list, num, beg, end)

If you can understand the bisect left the bisect right function will be work same as bisect left. it can take value by default in left side.

--

--