@@ 24-38 (lines=15) @@ | ||
21 | from subprocess import Popen |
|
22 | ||
23 | ||
24 | def chunk(seq, n): |
|
25 | """ |
|
26 | divide a sequence into equal sized chunks |
|
27 | (the last chunk may be smaller, but won't be empty) |
|
28 | """ |
|
29 | chunks = [] |
|
30 | some = [] |
|
31 | for element in seq: |
|
32 | if len(some) == n: |
|
33 | chunks.append(some) |
|
34 | some = [] |
|
35 | some.append(element) |
|
36 | if len(some) > 0: |
|
37 | chunks.append(some) |
|
38 | return chunks |
|
39 | ||
40 | ||
41 | def dechunk(chunks): |
@@ 24-38 (lines=15) @@ | ||
21 | from subprocess import Popen |
|
22 | ||
23 | ||
24 | def chunk(seq, n): |
|
25 | """ |
|
26 | divide a sequence into equal sized chunks |
|
27 | (the last chunk may be smaller, but won't be empty) |
|
28 | """ |
|
29 | chunks = [] |
|
30 | some = [] |
|
31 | for element in seq: |
|
32 | if len(some) == n: |
|
33 | chunks.append(some) |
|
34 | some = [] |
|
35 | some.append(element) |
|
36 | if len(some) > 0: |
|
37 | chunks.append(some) |
|
38 | return chunks |
|
39 | ||
40 | ||
41 | def dechunk(chunks): |