[issue27212] Doc for itertools, 'islice()' implementation have unwanted behavior for recipe 'consume()'
Raymond Hettinger
report at bugs.python.org
Fri Sep 9 16:44:00 EDT 2016
Raymond Hettinger added the comment:
The recipe should be modified to consume the initial values. Something like this:
start, stop, step = s.start or 0, s.stop or sys.maxsize, s.step or 1
for i in zip(range(0, start), it):
pass
The recipe needs to pass these tests:
it = iter('abcdefghi')
assert list(islice(it, 4, 4)) == []
assert list(it) == ['e', 'f', 'g', 'h', 'i']
assert(list(islice('ABCDEFG', 2)) == ['A', 'B'])
assert(list(islice('ABCDEFG', 2, 4)) == ['C', 'D'])
assert(list(islice('ABCDEFG', 2, None)) == ['C', 'D', 'E', 'F', 'G'])
assert(list(islice('ABCDEFG', 0, None, 2)) == ['A', 'C', 'E', 'G'])
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27212>
_______________________________________
More information about the Python-bugs-list
mailing list