1 2 3 4 5 6 7
from functools import reduce from itertools import product def cartesian(*items): for cart in product(*items): yield reduce(lambda x, y: x + y, cart)