title: Why does the generator get rewound to its beginning?
body: <p>I'm trying to implement a function that does this:</p>
  <p>Rotate a 2D infinite array by 45 degrees of a full turn, clockwise (this question is taken from <a href="http://www.codewars.com" rel="nofollow noreferrer">www.codewars.com</a>).</p>
  <p>For example (generators are represented with list notation):</p>
  <pre><code>rotate([[1,2,3,4,...],
          ['a','b','c',...],
          ['A','B',...],
          ['0',...],
          ...])
      == [[1],
          ['a',2],
          ['A','b',3],
          ['0','B','c',4],
          ...]
  </code></pre>
  <p>Inputs/outputs will be infinite generators of infinite generators. My solution is this:</p>
  <pre><code>def rotate(seq):
      row = 0
      generators = []
      while True:
          next_gen = next(seq)
          generators.append(next_gen)
          yield inner_generator(row, generators)
          row += 1
  
  
  def inner_generator(row, arr):
      while row &gt;= 0:
          next_value = next(arr[row])
          row -= 1
          yield next_value
  </code></pre>
  <p>However, the generators within the list <code>generators</code> get rewound to their beginning. For example, when the input is as in the example above, my function returns:</p>
  <pre><code>[[1], ['a', 1], ['A', 'a', 1], ['0', 'A', 'a', 1], ...]
  </code></pre>
  <p>instead of:</p>
  <pre><code>[[1], ['a', 2], ['A', 'b', 3], ['0', 'B', 'c', 4], ...]
  </code></pre>
  <p>What's the reason for this?</p>
  <p>My simple test is:</p>
  <pre><code>def gen_chars():
      def gen_row(j):
          while True:
              yield from j
      
      for k in ['1234', 'abc', 'AB', '0']:
          yield gen_row(k)
  
  
  
  seq1 = gen_chars()
  seq2 = rotate(seq1)
  g1 = next(seq2)
  g2 = next(seq2)
  
  
  for i in g2:
      print(i)
  </code></pre>
  <p>and it prints (as the content of the second generator, for instance) ['a', 1] intstead of ['a', 2].</p>