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>Here is a version that iterates through the list only once: </p>

<pre><code>start = 0
delta = 1
stop = delta 
grouped = []
group = []
event = [0.1, 0.6, 1.5, 3.4, 3.8, 4.1, 6.2, 8.5, 9.1, 9.5] 
for val in event:
    if start &lt; val &lt; stop:
        group.append(val)
    else:
        while val &gt; stop:
            start += delta
            stop += delta
        grouped.append(group)
        group = [val]

print(grouped) # [[0.1, 0.6], [1.5], [3.4, 3.8], [4.1], [6.2], [8.5]] 
</code></pre>

python list