nodes: 0, module; 1, function_definition; 2, function_name:sort_descendants; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, identifier:attr; 11, string:"name"; 12, comment:"""
          This function sort the branches of a given tree by
          considerening node names. After the tree is sorted, nodes are
          labeled using ascendent numbers.  This can be used to ensure
          that nodes in a tree with the same node names are always
          labeled in the same way. Note that if duplicated names are
          present, extra criteria should be added to sort nodes.
  
          Unique id is stored as a node._nid attribute
          """; 13, assignment; 14, identifier:n; 15, call; 16, block; 17, identifier:node2content; 18, call; 19, attribute; 20, argument_list; 21, if_statement; 22, attribute; 23, argument_list; 24, identifier:self; 25, identifier:traverse; 26, not_operator; 27, block; 28, identifier:self; 29, identifier:get_cached_content; 30, keyword_argument; 31, keyword_argument; 32, call; 33, expression_statement; 34, identifier:store_attr; 35, identifier:attr; 36, identifier:container_type; 37, identifier:list; 38, attribute; 39, argument_list; 40, call; 41, identifier:n; 42, identifier:is_leaf; 43, attribute; 44, argument_list; 45, attribute; 46, identifier:sort; 47, keyword_argument; 48, identifier:n; 49, identifier:children; 50, identifier:key; 51, lambda; 52, lambda_parameters; 53, call; 54, identifier:x; 55, identifier:str; 56, argument_list; 57, call; 58, identifier:sorted; 59, argument_list; 60, subscript; 61, identifier:node2content; 62, identifier:x
code: def sort_descendants(self, attr="name"):
          """
          This function sort the branches of a given tree by
          considerening node names. After the tree is sorted, nodes are
          labeled using ascendent numbers.  This can be used to ensure
          that nodes in a tree with the same node names are always
          labeled in the same way. Note that if duplicated names are
          present, extra criteria should be added to sort nodes.
  
          Unique id is stored as a node._nid attribute
          """
          node2content = self.get_cached_content(store_attr=attr, container_type=list)
          for n in self.traverse():
              if not n.is_leaf():
                  n.children.sort(key=lambda x: str(sorted(node2content[x])))