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

Victor Stinner victor.stinner at gmail.com
Thu May 4 12:50:36 EDT 2017


> 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 write chunks(seq, n), but it's much simpler to
implement and will work on all Python versions, enjoy!

Victor


More information about the Python-ideas mailing list