equal
deleted
inserted
replaced
150 if os.name != 'nt': |
150 if os.name != 'nt': |
151 _platformworker = _posixworker |
151 _platformworker = _posixworker |
152 _exitstatus = _posixexitstatus |
152 _exitstatus = _posixexitstatus |
153 |
153 |
154 def partition(lst, nslices): |
154 def partition(lst, nslices): |
155 '''partition a list into N slices of equal size''' |
155 '''partition a list into N slices of roughly equal size |
156 n = len(lst) |
156 |
157 chunk, slop = n / nslices, n % nslices |
157 The current strategy takes every Nth element from the input. If |
158 end = 0 |
158 we ever write workers that need to preserve grouping in input |
159 for i in xrange(nslices): |
159 we should consider allowing callers to specify a partition strategy. |
160 start = end |
160 ''' |
161 end = start + chunk |
161 for i in range(nslices): |
162 if slop: |
162 yield lst[i::nslices] |
163 end += 1 |
|
164 slop -= 1 |
|
165 yield lst[start:end] |
|