Hi,<br><br>Apologies if this has been discussed in this list before. Google has not been very helpful in locating any such<br>previous discussion.<br><br>Are there any promises made with regard to final state of the underlying sequence that islice slices?<br>

for example consider this<br><br>>>> from itertools import *<br clear="all">>>> c = count()<br>>>> list(islice(c, 1, 3, 50))<br>[1]<br>>>> c.next()<br>51<br><br>Now, the doc [1] says "If <em>stop</em> is <tt class="xref docutils literal"><span class="pre">None</span></tt>, then iteration
continues until the iterator is exhausted, if at all; otherwise, it stops at the
specified position".<br>It clearly is not stopping at stop (3).<br><br>Further, the doc gives an example of how this is *equivalent* to a generator defined in the same section. It turns out, these two are not exactly the<br>

same if the side-effect of the code is considered on the underlying sequence.<br><br>Redefining islice using the generator function defined in the doc gives different (and from one pov, expected) result<br>>>> def islice(iterable, *args):<br>

...     # islice('ABCDEFG', 2) --> A B<br>...<br>>>> c = count()<br>>>> list(islice(c, 1, 3, 50))<br>[1]<br>>>> c.next()<br>2<br><br>While "fixing" this should be rather easy in terms of the change in code required it might break any code depending<br>

on this seemingly incorrect behavior. <br> <br>[1]. <a href="http://docs.python.org/library/itertools.html#itertools.islice">http://docs.python.org/library/itertools.html#itertools.islice</a><br>-- <br>Regards<br>Shashank Singh<br>

<a href="mailto:shashank.sunny.singh@gmail.com" target="_blank">shashank.sunny.singh@gmail.com</a><br><a href="http://www.cse.iitb.ac.in/%7Eshashanksingh" target="_blank">http://www.cse.iitb.ac.in/~shashanksingh</a><br>