[Python-ideas] itertools.chunks()
João Bernardo
jbvsmo at gmail.com
Sat Apr 6 20:30:07 CEST 2013
Isn't it just
divmod(total, step)
João Bernardo
2013/4/6 Giampaolo Rodolà <g.rodola at gmail.com>
> 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/
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130406/02fbcc2e/attachment.html>
More information about the Python-ideas
mailing list