For a sequence of values, how can you calculate the index of X?

20 Views Asked by At

I first thought this would be easy but I can't think of a solution. Say you have a list of numbers with values between 0 and 1. I need a way to calculate what is the index of the interval in which X is. Here is a demonstration of what i'm trying to ask: the problem

So for example, A=[1,0.5,0.9,0.1,0.8,1,1,0,0.6,1]

If X = 2.8, i = 5 and A[i] = 0.8

If X = 2.3, i = 3 and A[i] = 0.9

For any list of values of any length, is a way to calculate this in a form I could actually use in an function ?