title: Why does Python's itertools.cycle need to create a copy of the iterable?
body: <p>The documentation for Python's itertools.cycle() gives a pseudo-code implementation as:</p>
  
  <pre><code>def cycle(iterable):
      # cycle('ABCD') --&gt; A B C D A B C D A B C D ...
      saved = []
      for element in iterable:
          yield element
          saved.append(element)
      while saved:
          for element in saved:
                yield element
  </code></pre>
  
  <p>Below, it states: "Note, this member of the toolkit may require significant auxiliary storage (depending on the length of the iterable)."</p>
  
  <p>I basically was going down this path, except I did this, which does not require creating a copy of the iterable:</p>
  
  <pre><code>def loop(iterable):
      it = iterable.__iter__()
  
      while True:
          try:
              yield it.next()
          except StopIteration:
              it = iterable.__iter__()
              yield it.next()
  
  x = {1, 2, 3}
  
  hard_limit = 6
  for i in loop(x):
      if hard_limit &lt;= 0:
          break
  
      print i
      hard_limit -= 1
  </code></pre>
  
  <p>prints:</p>
  
  <pre><code>1
  2
  3
  1
  2
  3
  </code></pre>
  
  <p>Yes, I realize my implementation wouldn't work for str's, but it could be made to. I'm more curious as to why it creates another copy. I have a feeling it has to do with garbage collection, but I'm not well studied in this area of Python.</p>
  
  <p>Thanks!</p>