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>you can do this with <code>itertools.groupby</code> pretty easily:</p>

<pre><code>from itertools import groupby
event.sort()
delta_t = 1
r = [list(v) for (k, v) in groupby(event, lambda v: v // delta_t)]
</code></pre>

python list