David Hirschfield <[EMAIL PROTECTED]> writes:
> So sequentialChunks([1,2,3,5,6,8,12]) returns:
> [[1,2,3],[5,6],[8],[12]]

Ugly and not too efficient: find the break points and use them to make
sub-lists.  

def sequentialChunks(l, stride=1):
   p = [0] + [i for i in xrange(1,len(l)) if l[i]-l[i-1] != stride] + [len(l)]
   return [l[p[i]:p[i+1]] for i in xrange(len(p)-1)]

print sequentialChunks([1,2,3,5,6,8,12])
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to