how to calculate average lenght of time in a list : I have a csv file with two columns: date and price. 
I am trying to figure out how long, on average the price stays within a certain range. Let say my values are [10, 7.7, 9.5, 15, 8.8, 9.3, 7.7, 16] For example when the value is between 8 - 9.9, how long on average before it is >14 (not going backwards). 9.5 passes 14 in 1 day. 8.8 in 3 days. 9.3 in 2 days. 7.7 in 1 day. So the average is (1 + 3 + 2 + 1 )/4 = 1.75 days.
I am trying to create a program that does that calculation for me but I am having problems.

first the  pseudocode: 

create new function

iterate over the rows (for i in rows:)

check for the presence of median price range where I want the check to start (if 8 < x < 9.9), store x as initial value variable y

time to reset and increment the index, for next row increment index i

when x leaves bound (if  x > 14) store index i in dictionary z (not sure this step makes sense)

after all rows are iterated through, average all indexes stored in z

code:


from itertools import*

list = [10, 7.7, 9.5, 15, 8.8, 9.3, 7.7, 16] (in reality this will be a csv file with rows)

def new_function()

	for i in list:

	while 8 < x < 9.99: 
	
	elif x > 14 (store index in z?)


average = sum(z)/len(z)

print(average)