I would like to generate a list of all the possible combinations of two lists. As for instance, given L=3;
list={0,1,2}; I would like to obtain the list {{0,0,0},{0,0,1},{0,0,2},{0,1,0},{0,2,0},{1,0,0},{2,0,0}}
I did it with the code:
f[d_, L_] := Module[{l, st}, l = Join[{d}, Table[0, {j, L - 1}]]; st = {}; AppendTo[st, Permutations@l]; Return[First@st]; ]; d = 2; L = 3; Flatten[Join[Table[f[j, L], {j, 0, d}]], 1] Is there a better way to do by combining lists?