import itertools


def sorted_classes_from_index_dict(idx_dct):
    """ Obtain classes from index dict, sorted by class index.

        :param idx_dct: A dictionary mapping atom keys to class indices.
        :type idx_dct: dict
        :returns: A tuple of tuples of keys for each class, sorted by class
            index.
        :rtype: tuple[tuple[int]]
    """
    keys = sorted(idx_dct.keys())
    clas = sorted(keys, key=idx_dct.__getitem__)
    cla_dct = tuple(
        tuple(c) for _, c in itertools.groupby(clas, key=idx_dct.__getitem__))
    return cla_dct