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>You can find the working sample down here:</p>

<pre><code>list = [0.0, 5.0, 2.0, 0.0, 0.30000000000000004]
listDict = {}

for idx, val in enumerate(list):
    for idx2, val2 in enumerate(list):
        if idx != idx2 and list[idx] != list[idx2] and abs(list[idx] - list[idx2]) &lt; 0.5:
            listDict[str(list[idx])] = True
            listDict[str(list[idx2])] = True

print (len(listDict))
</code></pre>

<p>And this is <a href="http://ideone.com/kX3DVL" rel="nofollow">the link</a> for the live sample.</p>

python python-3.x