Reputation: 103
Is there a way to generate a list of all the vector of length n witch the element are between 1 and 6 like this : this ? I only know how to do it for a specific n with nested for loop. Thank you
Upvotes: 0
Views: 63
Reputation: 9010
A function which takes a pool and a length:
from itertools import product
def generate_vectors(pool, length):
return list(product(pool, repeat=length))
generate_vectors(range(1,7), 3)
# [(1, 1, 1), (1, 1, 2), (1, 1, 3), ...]
Upvotes: 3