Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-05 Thread Erik
Hi Nick, On 05/05/17 08:29, Nick Coghlan wrote: And then given the proposed str.splitgroups() on the one hand, and the existing memoryview.cast() on the other, offering itertools.itergroups() as a corresponding building block specifically for working with streams of regular data would make sense

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-05 Thread Nick Coghlan
On 5 May 2017 at 08:20, Greg Ewing wrote: > Victor Stinner wrote: >> >> I prefer str.join() approach: write a single chunks() function which >> takes a sequence, instead of modifying all sequence types around the >> world ;-) > > > Even if a general sequence-chunking function is thought useful, >

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-04 Thread Victor Stinner
2017-05-05 0:20 GMT+02:00 Greg Ewing : > While most uses would probably be for short strings, I can > think of uses cases involving large ones. For example, to > format a hex dump into lines with 8 bytes per line and spaces > between the lines: For such specialized use case, write a C extension.

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-04 Thread Greg Ewing
Victor Stinner wrote: I prefer str.join() approach: write a single chunks() function which takes a sequence, instead of modifying all sequence types around the world ;-) Even if a general sequence-chunking function is thought useful, it might be worth providing a special-purpose one as a string

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-04 Thread Victor Stinner
> How about adding a chunks() and rchunks() function to sequences: > > [1,2,3,4,5,6,7].chunks(3) => [[1,2,3], [4,5,6], [7]] I prefer str.join() approach: write a single chunks() function which takes a sequence, instead of modifying all sequence types around the world ;-) It's less natural to writ

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-02 Thread Nick Coghlan
On 2 May 2017 at 22:10, wrote: > Steven D’Aprano was giving me an idea (in the bytes.hex delimiter > discussion): > > I had very often the use case that I want to split sequences into > subsequences of same size. > > How about adding a chunks() and rchunks() function to sequences: > > [1,2,3,4,5,

Re: [Python-ideas] Add a .chunks() method to sequences

2017-05-02 Thread Geoffrey Spear
On Tue, May 2, 2017 at 8:10 AM wrote: > Steven D’Aprano was giving me an idea (in the bytes.hex delimiter > discussion): > > > > I had very often the use case that I want to split sequences into > subsequences of same size. > > How about adding a chunks() and rchunks() function to sequences: > >

[Python-ideas] Add a .chunks() method to sequences

2017-05-02 Thread robert.hoelzl
Steven D’Aprano was giving me an idea (in the bytes.hex delimiter discussion): I had very often the use case that I want to split sequences into subsequences of same size. How about adding a chunks() and rchunks() function to sequences: [1,2,3,4,5,6,7].chunks(3) => [[1,2,3], [4,5,6], [7]] "1234“