code: def chunks(items, chunksize):
      
  
      items = iter(items)
      for first in items:
          chunk = chain((first,), islice(items, chunksize - 1))
          yield chunk
          deque(chunk, 0)
docs: Turn generator sequence into sequence of chunks.