This question already has an answer here:
- Get the cartesian product of a series of lists? 11 answers
Suppose we have a list L
. The cartesian product L x L
could be computed like this:
product = [(a,b) for a in L for b in L]
How can the cartesian power L x L x L x ... x L
(n times, for a given n) be computed, in a short and efficient way?