Вы можете использовать следующую рекурсивную функцию:
def f(p, n, i=1):
if p == 0:
return [[]]
return [[j, *l] for j in range(i, n) for l in f(p - 1, n, j + 1)]
так что:
print(f(1, 7))
print(f(2, 7))
print(f(3, 7))
выходы:
[[1], [2], [3], [4], [5], [6]]
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6]]
[[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 3, 4], [1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [1, 5, 6], [2, 3, 4], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6], [2, 5, 6], [3, 4, 5], [3, 4, 6], [3, 5, 6], [4, 5, 6]]