Q:

Generate all vector that respect a condition in Python

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

A:

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), ...]

