There is a list of numbers s = [1, 2, 3, 4, 5, 6, 7] . It is necessary to compile a two-dimensional array m[7**7][7] , containing in the rows all possible arrangements from s . Implemented a variant with random , but it is very slow ..
dx = 7 dy = 7 ** 7 m = [[1 for x in range(dx)] for y in range(dy)] i = 0 k = 0 while i < dy: for j in range(dx): m[i][j] = random.randint(1, 7) for d in range(i): if d != i and m[i] == m[d]: i -= 1 k += 1 i += 1 The same clarification: possible permutations and repetitions of numbers in any place. Those. variant [1, 1, 1, 1, 1, 1, 1] also correct.