'Return the standardised (right) coset table of self in H as
a list of lists.'

def coset_table(self, H):

    from itertools import chain, product
    if (not H.is_subgroup(self)):
        raise ValueError('The    argument    must    be    a    subgroup')
    T = self.coset_transversal(H)
    n = len(T)
    A = list(chain.from_iterable(((gen, (gen ** (-1))) for gen in self.generators)))
    table = []
    for i in range(n):
        row = [self._coset_representative((T[i] * x), H) for x in A]
        row = [T.index(r) for r in row]
        table.append(row)
    A = range(len(A))
    gamma = 1
    for (alpha, a) in product(range(n), A):
        beta = table[alpha][a]
        if (beta >= gamma):
            if (beta > gamma):
                for x in A:
                    z = table[gamma][x]
                    table[gamma][x] = table[beta][x]
                    table[beta][x] = z
                    for i in range(n):
                        if (table[i][x] == beta):
                            table[i][x] = gamma
                        elif (table[i][x] == gamma):
                            table[i][x] = beta
            gamma += 1
            if (gamma == (n - 1)):
                return table
