The following code works, but appears verbose.
def gen(l):
for x in range(l[0]):
for y in range(l[1]):
for z in range(l[2]):
yield [x, y, z]
l = [1, 2, 3]
print(list(gen(l)))
>>>[[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [0, 1, 2]]
My intention was to cut down on LOC with itertools.product. Here's what I came up with.
from itertools import product
def gen(l):
for x, y, z in product(map(range, l)):
yield [x, y, z]
l = [1, 2, 3]
print(list(gen(l)))
ValueError: not enough values to unpack (expected 3, got 1)
Is there a different way to use itertools.product so that there are enough values to unpack?