Re: [Python-Dev] [Python-ideas] itertools.chunks(iterable, size, fill=None)

I've run into the necessity of implementing chunks() again. Here is the code I've made from scratch. def chunks(seq, size): '''Cut sequence into chunks of given size. If `seq` length is not divisible by `size` without reminder, last chunk will have length less than size. >>> list( chunks([1,2,3,4,5,6,7], 3) ) [[1, 2, 3], [4, 5, 6], [7]] ''' endlen = len(seq)//size for i in range(endlen): yield [seq[i*size+n] for n in range(size)] if len(seq) % size: yield seq[endlen*size:] -- anatoly t. On Fri, Jun 29, 2012 at 11:32 PM, Georg Brandl <g.brandl@gmx.net> wrote:

See the "grouper" example in http://docs.python.org/library/itertools.html On Friday, August 31, 2012 11:28:33 PM UTC-7, anatoly techtonik wrote:

On Sat, Sep 1, 2012 at 5:42 PM, Miki Tebeka <miki.tebeka@gmail.com> wrote:
See the "grouper" example in http://docs.python.org/library/itertools.html
As was discussed before, the problem is visibility of the solution, not the implementation. If we can divide core Python API into levels where 0 is the less important and 10 is more, then `chunks` should be level above than it is now. -- anatoly t.

See the "grouper" example in http://docs.python.org/library/itertools.html On Friday, August 31, 2012 11:28:33 PM UTC-7, anatoly techtonik wrote:

On Sat, Sep 1, 2012 at 5:42 PM, Miki Tebeka <miki.tebeka@gmail.com> wrote:
See the "grouper" example in http://docs.python.org/library/itertools.html
As was discussed before, the problem is visibility of the solution, not the implementation. If we can divide core Python API into levels where 0 is the less important and 10 is more, then `chunks` should be level above than it is now. -- anatoly t.
participants (2)
-
anatoly techtonik
-
Miki Tebeka