title: python itertools: Using cycle with islice
body: <p>Question:</p>
  
  <p>I have the code below. I want to know why does it not matter whether or not I include the line with the comment in the code below.</p>
  
  <pre><code>#!/usr/bin/env python
  
  from itertools import *
  import time
  cc = cycle([ iter([1,2,3]), iter([4]) , iter([5,6]) ] )
  p = 3
  while p:
      try:
          for k in cc:
              print k.next()
      except StopIteration:
          p = p - 1
          cc = cycle(islice(cc,  p))  # this does not matter
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1
  4
  5
  2
  6
  3
  </code></pre>
  
  <p>Also checkout <code>roundrobin</code> recipe at</p>
  
  <p><a href="http://docs.python.org/2.7/library/itertools.html" rel="nofollow">http://docs.python.org/2.7/library/itertools.html</a> </p>
  
  <p>This code shows that <code>islice</code> is impacting <code>cc</code></p>
  
  <pre><code>#!/usr/bin/env python
  
  from itertools import *
  import time
  cc = cycle([ iter([1,2,3]), iter([4]) , iter([5,6]) ] )
  p = 3
  while p:
      try:
          for k in cc:
              print k,k.next()
      except StopIteration:
              print "stop iter"
              p = p - 1
              cc = cycle(islice(cc,  p)) 
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>&lt;listiterator object at 0x7f32bc50cfd0&gt; 1
  &lt;listiterator object at 0x7f32bc518050&gt; 4
  &lt;listiterator object at 0x7f32bc518090&gt; 5
  &lt;listiterator object at 0x7f32bc50cfd0&gt; 2
  &lt;listiterator object at 0x7f32bc518050&gt; stop iter
  &lt;listiterator object at 0x7f32bc518090&gt; 6
  &lt;listiterator object at 0x7f32bc50cfd0&gt; 3
  &lt;listiterator object at 0x7f32bc518090&gt; stop iter
  &lt;listiterator object at 0x7f32bc50cfd0&gt; stop iter
  </code></pre>