Alpha sort by the full chain of parents.
515088
def getSubOrder(existing):
    
    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_)
325986
def get_all_parent_edges(self):
        """"""
        all_parent_edges = set()
        for parent in self.parents:
            all_parent_edges.add((self.item_id, parent.item_id))
            all_parent_edges |= parent.get_all_parent_edges()
        return all_parent_edges
1049694
def no_missing_parents(data_wrapper):
    '''
    '''
    db = data_wrapper.data_block
    ids = np.setdiff1d(db[:, COLS.P], db[:, COLS.ID])[1:]
    return CheckResult(len(ids) == 0, ids.astype(np.int) + 1)
883194
def get_klass_parents(gi_name):
    '''
    
    '''
    res = []
    parents = __HIERARCHY_GRAPH.predecessors(gi_name)
    if not parents:
        return []
    __get_parent_link_recurse(parents[0], res)
    return res
840728
def do_selection_reduction_to_one_parent(selection):
        

        all_models_selected = selection.get_all()
        # check if all elements selected are on one hierarchy level -> TODO or in future are parts of sibling?!
        # if not take the state with the most siblings as the copy root
        parent_m_count_dict = {}
        for model in all_models_selected:
            parent_m_count_dict[model.parent] = parent_m_count_dict[model.parent] + 1 if model.parent in parent_m_count_dict else 1
        parent_m = None
        current_count_parent = 0
        for possible_parent_m, count in parent_m_count_dict.items():
            parent_m = possible_parent_m if current_count_parent < count else parent_m
        # if root no parent exist and only on model can be selected
        if len(selection.states) == 1 and selection.get_selected_state().state.is_root_state:
            parent_m = None
            # kick all selection except root_state
            if len(all_models_selected) > 1:
                selection.set(selection.get_selected_state())
        if parent_m is not None:
            # check and reduce selection
            for model in all_models_selected:
                if model.parent is not parent_m:
                    selection.remove(model)

        return parent_m
1286280
def sorted(cls, items, orders):
    ''''''
    return sorted(items, cmp=cls.multipleOrderComparison(orders))
254696
def parents(self):
        
        return TermList(unique_everseen(
            y for x in self for y in x.parents
        ))
1223581
public static void sortMenu(BaseComponent parent, int startIndex, int endIndex) {
        List<BaseComponent> items = parent.getChildren();
        int bottom = startIndex + 1;

        for (int i = startIndex; i < endIndex;) {
            BaseComponent item1 = items.get(i++);
            BaseComponent item2 = items.get(i);

            if (item1 instanceof BaseMenuComponent && item2 instanceof BaseMenuComponent && ((BaseMenuComponent) item1)
                    .getLabel().compareToIgnoreCase(((BaseMenuComponent) item2).getLabel()) > 0) {
                parent.swapChildren(i - 1, i);

                if (i > bottom) {
                    i -= 2;
                }
            }
        }
    }
367803
def walk_preorder(self):
        """"""
        yield self
        for child in self._children():
            for descendant in child.walk_preorder():
                yield descendant
197765
def rank(self):
        """"""
        r = np.empty(self.size, np.int)
        r[self.sorter] = np.arange(self.size)
        return r
597501
def find_best_akaike(list_of_fits):
        """"""
        res = sorted(list_of_fits, key=lambda x: x.aic)
        return res[0]
673903
function sortByOrdinal(extensions, done) {
    const sorted = extensions.sort((a, b) => {
        if (a.ordinal || b.ordinal) {
            if (!a.ordinal) return 1;
            if (!b.ordinal) return -1;
            if (a.ordinal < b.ordinal) return -1;
            return 1;
        }
        return a.pluginId.localeCompare(b.pluginId);
    });

    if (done) {
        done(sorted);
    }

    return sorted;
}
452248
def sort(self, attr):
        """"""
        self.entries = Sorter(self.entries, self.category, attr).sort_entries()
        return self
867410
def top(self, sort_by):
        """"""
        sort = sorted(self.results, key=sort_by)
        return sort
692468
def stable_sort_by(list)
      list.each_with_index.sort_by {|tag, i| [yield(tag), i] }.map(&:first)
    end
1285960
def sort_by_name(names):
    """"""

    def last_name_key(full_name):
        parts = full_name.split(' ')
        if len(parts) == 1:
            return full_name.upper()
        last_first = parts[-1] + ' ' + ' '.join(parts[:-1])
        return last_first.upper()

    return sorted(set(names), key=last_name_key)
471229
def top_class(self):
        """"""
        curr = self
        parent = self.parent
        while isinstance(parent, class_t):
            curr = parent
            parent = parent.parent
        return curr