On 06.04.13 15:50, Giampaolo RodolĂ wrote: > def chunks(total, step): > assert total >= step > while total > step: > yield step; > total -= step; > if total: > yield total For integers this is: (min(step, total - i) for i in range(0, total, step))