I have this function:
def sequentialChunk s(l, stride=1):
chunks = []
chunk = []
for i,v in enumerate(l[:-1]):
v2 = l[i+1]
if v2-v == stride:
if not chunk:
chunk.append(v)
chunk.append(v2 )
else:
if not chunk:
chunk.append(v)
chunks.append(c hunk)
chunk = []
if chunk:
chunks.append(c hunk)
return chunks
Which takes a list of numerical values "l" and splits it into chunks
where each chunk is sequential, where sequential means each value in a
chunk is
separated from the next by "stride".
So sequentialChunk s([1,2,3,5,6,8,12]) returns:
[[1,2,3],[5,6],[8],[12]]
I don't think the code above is the most efficient way to do this, but
it is relatively clear. I tried fiddling with list-comprehension ways of
accomplishing it, but kept losing track of things...so if anyone has a
suggestion, I'd appreciate it.
Thanks,
-Dave
--
Presenting:
mediocre nebula.
def sequentialChunk s(l, stride=1):
chunks = []
chunk = []
for i,v in enumerate(l[:-1]):
v2 = l[i+1]
if v2-v == stride:
if not chunk:
chunk.append(v)
chunk.append(v2 )
else:
if not chunk:
chunk.append(v)
chunks.append(c hunk)
chunk = []
if chunk:
chunks.append(c hunk)
return chunks
Which takes a list of numerical values "l" and splits it into chunks
where each chunk is sequential, where sequential means each value in a
chunk is
separated from the next by "stride".
So sequentialChunk s([1,2,3,5,6,8,12]) returns:
[[1,2,3],[5,6],[8],[12]]
I don't think the code above is the most efficient way to do this, but
it is relatively clear. I tried fiddling with list-comprehension ways of
accomplishing it, but kept losing track of things...so if anyone has a
suggestion, I'd appreciate it.
Thanks,
-Dave
--
Presenting:
mediocre nebula.
Comment