How to divide a list into a given time step
<p>I have a list, e.g.</p>

<pre><code>event = [0.1, 0.6, 1.5, 3.4, 3.8, 4.1, 6.2, 8.5, 9.1, 9.5]  
</code></pre>

<p>Where each item in the list is a event happened at time 0.1, time 0.6 etc.</p>

<p>I want to divide the list into a delta t, but how can this be done? All the other threads I have seen only discussed about splitting the list into equal parts, but in this case if we have delta t = 1, I want a list where 0.1 and 0.6 is together, and another for 1.5 etc.</p>

<p>Another possible solution:</p>

<pre><code>from collections import defaultdict


def split_list(lst, delta=1):
    start, end = 0, max(event)
    result = []

    while start &lt; end:
        start += delta
        group = filter(lambda x: x &gt; (start - delta) and x &lt; start, event)

        if group:
            result.append(group)

    return result

event = [0.1, 0.6, 1.5, 3.4, 3.8, 4.1, 6.2, 8.5, 9.1, 9.5]
print split_list(event)
# [[0.1, 0.6], [1.5], [3.4, 3.8], [4.1], [6.2], [8.5], [9.1, 9.5]]
</code></pre>

python list