code: def chunk(iterator, max_size):
      
      gen = iter(iterator)
      while True:
          chunked = list()
          for i, item in enumerate(gen):
              chunked.append(item)
              if i >= max_size - 1:
                  break
          if not chunked:
              return
          yield chunked
docs: Chunk a list/set/etc.
  
      :param iter iterator: The iterable object to chunk.
      :param int max_size: Max size of each chunk. Remainder chunk may be smaller.
  
      :return: Yield list of items.
      :rtype: iter