[Python-ideas] itertools.chunks()

Giampaolo Rodolà g.rodola at gmail.com
Sat Apr 6 20:02:30 CEST 2013


2013/4/6 MRAB <python at 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.

--- Giampaolo
https://code.google.com/p/pyftpdlib/
https://code.google.com/p/psutil/
https://code.google.com/p/pysendfile/



More information about the Python-ideas mailing list