nodes: 0, module; 1, function_definition; 2, function_name:_restricted_growth_notation; 3, parameters; 4, block; 5, identifier:l; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, for_statement; 12, return_statement; 13, comment:""" The clustering returned by the hcluster module gives group
          membership without regard for numerical order This function preserves
          the group membership, but sorts the labelling into numerical order """; 14, assignment; 15, assignment; 16, tuple_pattern; 17, call; 18, block; 19, assignment; 20, tuple_pattern; 21, call; 22, block; 23, call; 24, identifier:list_length; 25, call; 26, identifier:d; 27, call; 28, identifier:i; 29, identifier:element; 30, identifier:enumerate; 31, argument_list; 32, expression_statement; 33, identifier:l2; 34, binary_operator:[None] * list_length; 35, identifier:name; 36, identifier:index_list; 37, identifier:enumerate; 38, argument_list; 39, for_statement; 40, identifier:tuple; 41, argument_list; 42, identifier:len; 43, argument_list; 44, identifier:defaultdict; 45, argument_list; 46, identifier:l; 47, call; 48, list; 49, identifier:list_length; 50, call; 51, identifier:index; 52, identifier:index_list; 53, block; 54, identifier:l2; 55, identifier:l; 56, identifier:list; 57, attribute; 58, argument_list; 59, None; 60, identifier:sorted; 61, argument_list; 62, expression_statement; 63, subscript; 64, identifier:append; 65, identifier:i; 66, call; 67, keyword_argument; 68, assignment; 69, identifier:d; 70, identifier:element; 71, attribute; 72, argument_list; 73, identifier:key; 74, identifier:min; 75, subscript; 76, identifier:name; 77, identifier:d; 78, identifier:values; 79, identifier:l2; 80, identifier:index
code: def _restricted_growth_notation(l):
          """ The clustering returned by the hcluster module gives group
          membership without regard for numerical order This function preserves
          the group membership, but sorts the labelling into numerical order """
  
          list_length = len(l)
  
          d = defaultdict(list)
          for (i, element) in enumerate(l):
              d[element].append(i)
  
          l2 = [None] * list_length
  
          for (name, index_list) in enumerate(sorted(d.values(), key=min)):
              for index in index_list:
                  l2[index] = name
  
          return tuple(l2)