How to generate all possible combination tuples of sequential series of N numbers in Python

1 Answer

0 votes
from itertools import product 
 
N = 3
  
result = [element for element in product(range(1, N + 1), repeat = N)] 
  
print(result) 



'''
run:

[(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 3, 1), 
(1, 3,2), (1, 3, 3), (2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 2, 1), (2, 2, 2), 
(2, 2, 3), (2,3, 1), (2, 3, 2), (2, 3, 3), (3, 1, 1), (3, 1, 2), (3, 1, 3), 
(3, 2, 1), (3, 2, 2), (3, 2, 3), (3, 3, 1), (3, 3, 2), (3, 3, 3)]

'''

 



answered Dec 9, 2019 by avibootz

Related questions

...