# how to generate all list combinations from a list

Given a list such as lis={1,2,3} how can one generate all permutations but as list, like this (order matters)

{{ 1,2,3 },   (*First level can be found using Permutations[{1,2,3}]*)
{ 1,3,2 },
{ 2,1,3 },
{ 2,3,1 },
{ 3,1,2 },
{ 3,2,1 },

{ {1}, {2,3} },  (*but what about these?*)
{ {1}, {3,2} },
{ {2}, {1,3} },
{ {2}, {3,1} },
{ {3}, {1,2} },
{ {3}, {2,1} },
{ {1,2}, {3} },
{ {2,1}, {3} },
{ {1,3}, {2} },
{ {3,1}, {2} },
{ {2,3}, {1} },
{ {3,2}, {1} },

{ {1},{2},{3}},  (*last level, can be obtained from first level *)
{ {1},{3},{2}},  (*by making each element in that, as a list*)
{ {2},{1},{3}},
{ {2},{3},{1}},
{ {3},{1},{2}},
{ {3},{2},{1}},

}


It is similar to Permutations but with partition to lists as well. I looked at Subsets, Partition and number of posts, but did not see anything similar.

You may use Permutations and IntegerPartitions with TakeList.

With

permutationsList[list_] :=
Flatten[#, 1] &@
Through@(
Function[{p}, Map[TakeList[#, p] &]] /@
Sort@Flatten[Permutations /@ IntegerPartitions@Length@list, 1]
)@Permutations[list]


Then

permutationsList@Range@3 //Column

{{1,2,3}}
{{1,3,2}}
{{2,1,3}}
{{2,3,1}}
{{3,1,2}}
{{3,2,1}}
{{1},{2,3}}
{{1},{3,2}}
{{2},{1,3}}
{{2},{3,1}}
{{3},{1,2}}
{{3},{2,1}}
{{1,2},{3}}
{{1,3},{2}}
{{2,1},{3}}
{{2,3},{1}}
{{3,1},{2}}
{{3,2},{1}}
{{1},{2},{3}}
{{1},{3},{2}}
{{2},{1},{3}}
{{2},{3},{1}}
{{3},{1},{2}}
{{3},{2},{1}}


Hope this helps.

There are 24 permutations to be chosen in groups of six in the original query.

alist = {1, 2, 3}

s = Permutations[alist, {3}]

{{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}}


x1 = Map[Partition[#, UpTo[1]] &, s]

{{{1}, {2}, {3}}, {{1}, {3}, {2}}, {{2}, {1}, {3}}, {{2}, {3}, {1}}, \
{{3}, {1}, {2}}, {{3}, {2}, {1}}}


x2 = Map[Partition[#, UpTo[2]] &, s]

   {{{1, 2}, {3}}, {{1, 3}, {2}}, {{2, 1}, {3}}, {{2, 3}, {1}}, {{3,
1}, {2}}, {{3, 2}, {1}}}


x3 = Map[Partition[#, UpTo[3]] &, s]

{{{1, 2, 3}}, {{1, 3, 2}}, {{2, 1, 3}}, {{2, 3, 1}}, {{3, 1, 2}}, {{3,
2, 1}}}


Join[x1, x2, x3]

Gets the job done using the UpTo specification. x2 will need to be reversed and added to the final list.