I want to make a list like this:
seq = [1,2,3]
\# implementation
print(result) \# [[1], [1,2], [1,2,3], [2], [2,3], [3]]
I want to make a list like this:
seq = [1,2,3]
\# implementation
print(result) \# [[1], [1,2], [1,2,3], [2], [2,3], [3]]
You can use itertools combination : https://docs.python.org/3/library/itertools.html#itertools.combinations
You can have a look at this answer for more details
Finally I could find a solution by myself:
N = 3
print([list(range(i, j)) for i in range(1,N+2) for j in range(i+1,N+2)])
or,
N = 3
lis = [list(range(i + 1, j + 1)) for (i, j) in itertools.combinations(list(range(N + 1)), 2)]
print(lis)
Thank you!