import bisect
c=[1,2,2,2,3,4,7]
position=bisect.bisect(c,2)
position#this will give the position of last occurence of 2
position5=bisect.bisect(c,5)#if element is not present then this will return after which position the element must be present
position5
Please Update below given code:
import bisect c=[1,2,2,2,3,4,7] position=bisect.bisect(c,2) position#this will give the position of last occurence of 2 position5=bisect.bisect(c,5)#if element is not present then this will return after which position the element must be present position5
Output: 4 6