code: def prune_overridden(ansi_string):
      
      multi_seqs = set(p for p in RE_ANSI.findall(ansi_string) if ';' in p[1])  # Sequences with multiple color codes.
  
      for escape, codes in multi_seqs:
          r_codes = list(reversed(codes.split(';')))
  
          # Nuke everything before {/all}.
          try:
              r_codes = r_codes[:r_codes.index('0') + 1]
          except ValueError:
              pass
  
          # Thin out groups.
          for group in CODE_GROUPS:
              for pos in reversed([i for i, n in enumerate(r_codes) if n in group][1:]):
                  r_codes.pop(pos)
  
          # Done.
          reduced_codes = ';'.join(sorted(r_codes, key=int))
          if codes != reduced_codes:
              ansi_string = ansi_string.replace(escape, '\033[' + reduced_codes + 'm')
  
      return ansi_string
docs: Remove color codes that are rendered ineffective by subsequent codes in one escape sequence then sort codes.
  
      :param str ansi_string: Incoming ansi_string with ANSI color codes.
  
      :return: Color string with pruned color sequences.
      :rtype: str