This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients ezio.melotti, python-dev, rhettinger, serhiy.storchaka, techtonik, terry.reedy
Date 2013-05-08.15:44:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368027892.44.0.548965125863.issue17862@psf.upfronthosting.co.za>
In-reply-to
Content
A week ago I implemented chunks() on C for issue17804. This is an equivalent of such Python code for unlimited sequences:

    def chunks(seq, size, start=0):
        for i in itertools.count(start, size):
            yield seq[i: i + size]

or simpler for limited sequences:

    def chunks(seq, size, start=0):
        for i in range(start, len(seq), size):
            yield seq[i: i + size]

Later I gave up the idea when I saw the insignificance of the benefits. Personally I have such arguments against including it in stdlib:

1. While C implemented chunks() is faster than manual iteration, speed up of real loops is not worth the use of special function.

2. This idiom is used less than I expected (about two dozen times in stdlib, not counting tests and tools) and use chunks() saves too little number of lines. In any case Python implementation is only 2-3 lines.

3. This function is not very well suited for the itertools module, because it works with sequences and not with iterators.
History
Date User Action Args
2013-05-08 15:44:52serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, terry.reedy, techtonik, ezio.melotti, python-dev
2013-05-08 15:44:52serhiy.storchakasetmessageid: <1368027892.44.0.548965125863.issue17862@psf.upfronthosting.co.za>
2013-05-08 15:44:52serhiy.storchakalinkissue17862 messages
2013-05-08 15:44:52serhiy.storchakacreate