Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 8834f8861b
Fetching contributors…

Cannot retrieve contributors at this time

27 lines (21 sloc) 0.64 kB
def bucketize(sequence, max_size):
buckets = []
if not sequence:
return buckets
for i, each in enumerate(sequence):
if not i:
bucket = []
elif not i % max_size:
buckets.append(bucket)
bucket = []
bucket.append(each)
if bucket:
buckets.append(bucket)
return buckets
def test_bucketize():
buckets = bucketize(range(1, 12), 5)
assert buckets == [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11]]
buckets = bucketize(range(1, 11), 5)
assert buckets == [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
if __name__ == '__main__':
test_bucketize()
Jump to Line
Something went wrong with that request. Please try again.