Isn't it just

   divmod(total, step)

João Bernardo


2013/4/6 Giampaolo Rodolà <g.rodola@gmail.com>
2013/4/6 MRAB <python@mrabarnett.plus.com>:
> On 06/04/2013 13:50, Giampaolo Rodolà wrote:
>>
>> def chunks(total, step):
>>      assert total >= step
>>      while total > step:
>>          yield step;
>>          total -= step;
>>      if total:
>>          yield total
>>
> Why shouldn't total be less than step?
>
> def chunks(total, step):
>     while total >= step:
>         yield step
>         total -= step
>     if total > 0:
>         yield total

I agree the assert statement can be removed.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas