how to find the consecutive items in the list that are in a specific range in python
<p>Having the following python list [0.0, 5.0, 2.0, 0.0, 0.30000000000000004] I'd like to return the count of the longest consecutive sequence of items less than 0.5</p>

<p>Expected result:
[0.0, 5.0, 2.0, 0.0, 0.30000000000000004] should give an output of 2</p>

<p>Possible, but unstable approach:</p>

<pre><code>def number_of_consecutive(data, min_threshold, max_threshold):

    sum_consec, max_value = 0,0

    for element in data:
        if element &lt;= max_threshold and element &gt;= min_threshold:
            sum_consec += 1
            if sum_consec &gt; max_value:
                max_value = sum_consec
        else:
            sum_consec = 0
    return max_value
</code></pre>

<p>To find elements in range 0 to 0.5 for given list:</p>

<pre><code>print number_of_consecutive([0.0, 5.0, 2.0, 0.0, 0.30000000000000004], 0.0, 0.5)
"2"
</code></pre>

python python-3.x