Serhiy Storchaka added the comment:
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.
----------
keywords: +patch
nosy: +serhiy.storchaka
Added file: http://bugs.python.org/file30177/iter_chunks.diff
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17862>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com