Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

bisect_left in python

import bisect

'''
bisect_left finds and returns the index where an element can be inserted 
and still maintain sorted order of the list
'''


			  #5,6,7,
arr = [1,2,3,4,      8,9,10]
#Index:0,1,2,3,4      ,5,6
x = 5
ans = bisect.bisect_left(arr, x)
print(ans) # 4
			  
arr = [0,1,2,3,4,5,5,8,9,10]
#Index:0,1,2,3,4,5,6,7,8
x = 5
ans = bisect.bisect_left(arr, x)
print(ans) # 5
Source by pythontic.com #
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
8+6 =