Message188723
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. |
|
Date |
User |
Action |
Args |
2013-05-08 15:44:52 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, terry.reedy, techtonik, ezio.melotti, python-dev |
2013-05-08 15:44:52 | serhiy.storchaka | set | messageid: <1368027892.44.0.548965125863.issue17862@psf.upfronthosting.co.za> |
2013-05-08 15:44:52 | serhiy.storchaka | link | issue17862 messages |
2013-05-08 15:44:52 | serhiy.storchaka | create | |
|