Say I have a list $L$ where the elements can be sorted into some canonical order. I want to use Tuples[L,m]
but I only want the output lists to be sorted and without repetition at any level. What I've currently got is
pretup = Tuples[L, m];
nextup = Table[Sort[pretup[[i]]], {i, 1, Length[L]^m}];
nextup = DeleteDuplicates[nextup];
finaltup = {};
Do[If[Length[DeleteDuplicates[nextup[[i]]]] == Length[nextup[[i]]],
AppendTo[finaltup, nextup[[i]]]], {i, 1, Length[nextup]}]
finaltup
but this is very inefficient. It first constructs all the possible combinations, then sorts them, then filters out duplicate sublists, then filters out duplicates within the sublists. Is there a faster way to do this? If so, what is it?
L
andm
. Thanks. $\endgroup$Subsets[L, {m}]
$\endgroup$