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

robert.hoelzl at posteo.de robert.hoelzl at posteo.de
Tue May 2 08:10:13 EDT 2017

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“.chunks(2) => [“12“, “34“]

(this could then be used to emulate stevens proposal: “ “.join(“1234567“.chunks(2)) => “12 34 56 7“)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170502/e6a5d3fd/attachment-0001.html>

More information about the Python-ideas mailing list