On Sat, Apr 6, 2013 at 3:50 PM, Giampaolo Rodolà <g.rodola@gmail.com> wrote:
def chunks(total, step):
    assert total >= step
    while total > step:
        yield step;
        total -= step;
    if total:
        yield total

>>> chunks(12, 4)
[4, 4, 4]
>>> chunks(13, 4)
[4, 4, 4, 1]


I'm not sure how appropriate "chunks" is as a name for such a function.

This name is better to be reserved for chunking actual data rather than indexes:
http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
 
Now I wonder, would it make sense to have something like this into
itertools module?
-- 
anatoly t.