code: def reduce(self, colors):
          
          need_reset = False
          line = []
          for color, items in itertools.groupby(colors):
              if color is None:
                  if need_reset:
                      line.append("\x1b[49m")
                      need_reset = False
                  line.append(self.pad * len(list(items)))
              elif color == "EOL":
                  if need_reset:
                      line.append("\x1b[49m")
                      need_reset = False
                      yield "".join(line)
                  else:
                      line.pop()
                      yield "".join(line)
                  line = []
              else:
                  need_reset = True
                  line.append("\x1b[48;5;%dm%s" % (
                      color, self.pad * len(list(items))))
docs: Converts color codes into optimized text
  
          This optimizer works by merging adjacent colors so we don't
          have to repeat the same escape codes for each pixel.  There is
          no loss of information.
  
          :param colors: Iterable yielding an xterm color code for each
                         pixel, None to indicate a transparent pixel, or
                         ``'EOL'`` to indicate th end of a line.
  
          :return: Yields lines of optimized text.