split a list according to size of float entries
<p>I have a list of floats where the size at each sequential index can vary.
i.e.</p>

<pre><code>float_list = [167.233, 95.6242, 181.367, 20.6354, 147.505, 41.9396, 20.3126]
</code></pre>

<p>What I am trying to do is to split the list according to the size of the floats in the indices. In particular, if the float at one index is less than that at the index before, then group the indices together to return the total number of indices that are less than those before.</p>

<p>For example, if we start from the first index the value is 167.233. Because the value at the next index, 95.6242, is smaller than that of the one prior, I would like to group these two together to return their length i.e. 2.</p>

<p>The third index is larger than the second, so this becomes the new 'benchmark'. Since the following index is smaller than that at the third, this returns the length 2.
The fifth index is the next 'benchmark' and the floats at the remaining indices decrease, therefore returning the length of those indices 3.</p>

<p>The way in which I would like this returned, is a list of the length of those indices i.e [2,2,3]</p>

<p>Apologies in advance if this is confusing, it is difficult to explain in words.</p>

<p>You can also do it like following:</p>

<pre><code>def group_list(l):
    if not l:
        return []

    result = [0]
    prev = l[0] + .1
    for el in l:
        if el &lt; prev:
            result[-1] += 1
        else:
            result.append(1)
        prev = el

    return result

&gt;&gt;&gt; group_list([167.233, 95.6242, 181.367, 20.6354, 147.505, 41.9396, 20.3126])
[2, 2, 3]
&gt;&gt;&gt; group_list([167.233, 95.6242, 1.367, 20.6354, 147.505, 41.9396, 20.3126])
[3, 1, 3]
&gt;&gt;&gt; group_list([167.233, 95.6242, 1.367, 20.6354, 147.505, 41.9396, 70.3126])
[3, 1, 2, 1]
&gt;&gt;&gt; group_list([-167.233, 95.6242, 1.367, 20.6354, 147.505, 41.9396, 70.3126])
[1, 2, 1, 2, 1]
</code></pre>

python