I have a list of elements with certain values of type float. I want to iterate over the elements and count them if they are over a certain value, but also only count them if they appear over the treshold value a minimum_count of times. So for example, if a have following input:
list_of_values = [2.0, 2.0, 2.0, 2.0, 0, 0, 2.0, 2.0, 2.0, 0, 0]
treshold_value = 1.0
minimum_count = 4
the answer should be 4, since the treshold_value 1.0 is consecutively exceeded 4 times only at indexes 0-3. I now have the code below,
for value in list_of_values:
if value >= treshold_value:
counter += 1
if counter >= (minimum_count):
time_use += 1
if value < min_treshold_value:
counter = 0
print(time_use)
I know there should be some pythonic way to achieve this :)
Edit: The sum of all consecutive subsequence values over the threshold should be counted.