I have a sorted list, for example x = [120, 99, 90, 90, 40, 5, 5, 5, 1, 1].
I want to find the index of the last element that is greater than a variable, for example limit = 30. In this example, I want to get 4, because that's the index of 40 (and 5 is lower than 30).
How can I do that efficiently in python?
I can do looping like this:
def filtering(x, limit):
for i,elem in enumerate(x):
if elem <=limit:
return i-1
return i
But I was thinking if there is any better way / numpy function to do this. Thanks!
O(log n)time instead ofO(n)