I've got a certain class of lists with, say, 4 elements, that are lists themselves. E.g. {{1, 2, 3}, {4}, {5, 6}, {7}}
.
I'd like to find a way to generate a list that contains all of the cousins of this list where the sublists are permuted in all possible ways.
With the previous example, this list would have size $3!\times 2!=12$.
To be really definite, in the simpler case of {{1, 2},{3,4}}
, I'd want to obtain {{{1, 2},{3,4}},{{2,1},{3,4}},{{1, 2},{4,3}},{{2,1},{4,3}}}
.
I feel like there should be a one line code for this but I couldn't figure it out.
Permutations/@{{1, 2, 3}, {4}, {5, 6}, {7}}
returns a reasonably interesting list, out of which I'm unable to extract what I want in a simple (i.e. Mathematica) way. Using further Pick
starts to demand that I get more explicitly certain lists or binary trees or so...
Tuples[Permutations /@ {{1, 2, 3}, {4}, {5, 6}, {7}}]
suit your needs? $\endgroup$Tuples
is so much simpler thanOuter
for this... If you post that as an answer, I'll delete mine. $\endgroup$