code: def batch(iterable, chunk_size):
      
      i = iter(iterable)
      while True:
          r = list(itertools.islice(i, chunk_size))
          if not r:
              break
          yield r
docs: Return items from iterable in chunk_size bits.
  
      If len(iterable) % chunk_size > 0, the last item returned will be shorter.