import itertools


def classes_of_combinations_with_replacement(n, k):
    """
    Return all [n]**k regrouped by the permutations
    """
    result = []
    for x in itertools.combinations_with_replacement(range(n), k):
        result.append(list(set(itertools.permutations(x))))
    return result