nodes: 0, module; 1, function_definition; 2, function_name:getSubOrder; 3, parameters; 4, block; 5, identifier:existing; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, function_definition; 10, for_statement; 11, expression_statement; 12, function_definition; 13, return_statement; 14, comment:""" Alpha sort by the full chain of parents. """; 15, assignment; 16, assignment; 17, function_name:getDepth; 18, parameters; 19, block; 20, identifier:id_; 21, identifier:existing; 22, block; 23, call; 24, function_name:key_; 25, parameters; 26, block; 27, call; 28, identifier:alpha; 29, subscript; 30, identifier:depths; 31, dictionary; 32, identifier:id_; 33, if_statement; 34, expression_statement; 35, identifier:print; 36, argument_list; 37, identifier:id_; 38, return_statement; 39, identifier:sorted; 40, argument_list; 41, call; 42, integer:0; 43, comparison_operator:id_ in depths; 44, block; 45, else_clause; 46, call; 47, call; 48, subscript; 49, identifier:depths; 50, keyword_argument; 51, identifier:list; 52, argument_list; 53, identifier:id_; 54, identifier:depths; 55, return_statement; 56, block; 57, identifier:getDepth; 58, argument_list; 59, identifier:sorted; 60, argument_list; 61, identifier:depths; 62, identifier:id_; 63, identifier:key; 64, identifier:key_; 65, call; 66, subscript; 67, if_statement; 68, identifier:id_; 69, call; 70, identifier:zip; 71, argument_list; 72, identifier:depths; 73, identifier:id_; 74, comparison_operator:id_ in existing; 75, block; 76, else_clause; 77, attribute; 78, argument_list; 79, list_splat; 80, identifier:id_; 81, identifier:existing; 82, expression_statement; 83, expression_statement; 84, return_statement; 85, block; 86, identifier:depths; 87, identifier:values; 88, call; 89, assignment; 90, assignment; 91, subscript; 92, return_statement; 93, identifier:sorted; 94, argument_list; 95, identifier:names_above; 96, call; 97, subscript; 98, binary_operator:names_above + [existing[id_]['rec']['label']]; 99, identifier:depths; 100, identifier:id_; 101, list; 102, generator_expression; 103, keyword_argument; 104, identifier:getDepth; 105, argument_list; 106, identifier:depths; 107, identifier:id_; 108, identifier:names_above; 109, list; 110, string; 111, tuple; 112, for_in_clause; 113, identifier:key; 114, lambda; 115, subscript; 116, subscript; 117, identifier:k; 118, subscript; 119, pattern_list; 120, call; 121, lambda_parameters; 122, subscript; 123, subscript; 124, string; 125, subscript; 126, string; 127, subscript; 128, string; 129, identifier:k; 130, identifier:v; 131, attribute; 132, argument_list; 133, identifier:a; 134, identifier:a; 135, integer:1; 136, identifier:existing; 137, identifier:id_; 138, string_content:sc; 139, subscript; 140, string; 141, string_content:label; 142, identifier:v; 143, string; 144, string_content:label; 145, identifier:existing; 146, identifier:items; 147, identifier:existing; 148, identifier:id_; 149, string_content:rec; 150, string_content:rec
code: def getSubOrder(existing):
      """ Alpha sort by the full chain of parents. """
      alpha = list(zip(*sorted(((k, v['rec']['label']) for k, v in existing.items()), key=lambda a: a[1])))[0]
      depths = {}
      def getDepth(id_):
          if id_ in depths:
              return depths[id_]
          else:
              if id_ in existing:
                  names_above = getDepth(existing[id_]['sc'])
                  depths[id_] = names_above + [existing[id_]['rec']['label']]
                  return depths[id_]
              else:
                  return ['']
  
      for id_ in existing:
          getDepth(id_)
  
      print(sorted(depths.values()))
  
      def key_(id_):
          return depths[id_]
  
      return sorted(depths, key=key_)