[Python-ideas] itertools.chunks()

Serhiy Storchaka storchaka at gmail.com
Sat Apr 6 22:13:05 CEST 2013


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))





More information about the Python-ideas mailing list