nodes: 0, module; 1, function_definition; 2, function_name:prune_overridden; 3, parameters; 4, block; 5, identifier:ansi_string; 6, expression_statement; 7, expression_statement; 8, comment:# Sequences with multiple color codes.; 9, for_statement; 10, return_statement; 11, comment:"""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
      """; 12, assignment; 13, pattern_list; 14, identifier:multi_seqs; 15, block; 16, identifier:ansi_string; 17, identifier:multi_seqs; 18, call; 19, identifier:escape; 20, identifier:codes; 21, expression_statement; 22, comment:# Nuke everything before {/all}.; 23, try_statement; 24, comment:# Thin out groups.; 25, for_statement; 26, comment:# Done.; 27, expression_statement; 28, if_statement; 29, identifier:set; 30, generator_expression; 31, assignment; 32, block; 33, except_clause; 34, identifier:group; 35, identifier:CODE_GROUPS; 36, block; 37, assignment; 38, comparison_operator:codes != reduced_codes; 39, block; 40, identifier:p; 41, for_in_clause; 42, if_clause; 43, identifier:r_codes; 44, call; 45, expression_statement; 46, identifier:ValueError; 47, block; 48, for_statement; 49, identifier:reduced_codes; 50, call; 51, identifier:codes; 52, identifier:reduced_codes; 53, expression_statement; 54, identifier:p; 55, call; 56, comparison_operator:';' in p[1]; 57, identifier:list; 58, argument_list; 59, assignment; 60, pass_statement; 61, identifier:pos; 62, call; 63, block; 64, attribute; 65, argument_list; 66, assignment; 67, attribute; 68, argument_list; 69, string; 70, subscript; 71, call; 72, identifier:r_codes; 73, subscript; 74, identifier:reversed; 75, argument_list; 76, expression_statement; 77, string; 78, identifier:join; 79, call; 80, identifier:ansi_string; 81, call; 82, identifier:RE_ANSI; 83, identifier:findall; 84, identifier:ansi_string; 85, string_content:;; 86, identifier:p; 87, integer:1; 88, identifier:reversed; 89, argument_list; 90, identifier:r_codes; 91, slice; 92, subscript; 93, call; 94, string_content:;; 95, identifier:sorted; 96, argument_list; 97, attribute; 98, argument_list; 99, call; 100, binary_operator:r_codes.index('0') + 1; 101, list_comprehension; 102, slice; 103, attribute; 104, argument_list; 105, identifier:r_codes; 106, keyword_argument; 107, identifier:ansi_string; 108, identifier:replace; 109, identifier:escape; 110, binary_operator:'\033[' + reduced_codes + 'm'; 111, attribute; 112, argument_list; 113, call; 114, integer:1; 115, identifier:i; 116, for_in_clause; 117, if_clause; 118, integer:1; 119, identifier:r_codes; 120, identifier:pop; 121, identifier:pos; 122, identifier:key; 123, identifier:int; 124, binary_operator:'\033[' + reduced_codes; 125, string; 126, identifier:codes; 127, identifier:split; 128, string; 129, attribute; 130, argument_list; 131, pattern_list; 132, call; 133, comparison_operator:n in group; 134, string; 135, identifier:reduced_codes; 136, string_content:m; 137, string_content:;; 138, identifier:r_codes; 139, identifier:index; 140, string; 141, identifier:i; 142, identifier:n; 143, identifier:enumerate; 144, argument_list; 145, identifier:n; 146, identifier:group; 147, string_content; 148, string_content:0; 149, identifier:r_codes; 150, escape_sequence:\033
code: def prune_overridden(ansi_string):
      """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
      """
      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