title: Converting generators to lists overwrites the values in Python
body: <p>I have this piece of code in Python 3.5 that implements generators for  batching of potentially large buffered data:</p>
  
  <pre><code>def batched_data(data, size=20):                             
      batch = []  
      for d in data:                                                                                                                                                                                
          batch.append(d)
          if len(batch) == size:
              yield batch
              batch.clear()
      yield batch
  
  def buffered_data(data, bufminsize=10, bufmaxsize=20): 
      diter = iter(data)                                                                                            
      buffer = collections.deque(next(diter) for _ in range(bufmaxsize))
  
      while buffer:                                                                                                                                                                                 
          yield buffer.popleft()
          if len(buffer) &lt; bufminsize:
              buffer.extend(
                  next(diter) for _ in range(bufmaxsize - len(buffer)))
  
  def batched_buffered_data(data, bufsize=100, batch=20):      
      yield from batched_data(
          buffered_data(data, bufmaxsize=bufsize, 
                        bufminsize=bufsize - batch),
          size=batch)
  </code></pre>
  
  <p>Now, when I initialize my generator and traverse the batches in a for-loop, everything's fine:</p>
  
  <pre><code>In [351]: gen = batched_buffered_data(range(27), bufsize=10, batch=7)
  In [352]: for g in gen:
       ...:     print(g)
       ...:
  [0, 1, 2, 3, 4, 5, 6]
  [7, 8, 9, 10, 11, 12, 13]
  [14, 15, 16, 17, 18, 19, 20]
  [21, 22, 23, 24, 25, 26]
  </code></pre>
  
  <p>However, when I try to use list comprehension or conversion using <code>list</code>, this happens:</p>
  
  <pre><code>In [353]: gen = batched_buffered_data(range(27), bufsize=10, batch=7)
  
  In [354]: list(gen)
  Out[354]: 
  [[21, 22, 23, 24, 25, 26],
   [21, 22, 23, 24, 25, 26],
   [21, 22, 23, 24, 25, 26],
   [21, 22, 23, 24, 25, 26]]
  </code></pre>
  
  <p>I am really puzzled about this. There must be some sort of mutable elements involved, but I really don't know what's behind this behavior.</p>