# Tuples of elements from list excluding anything with repeated values

What I would like to do is the following.

For a given list of elements; say (0,1,2,3,4) I would like to obtain all possible combinations of five, but not the ones with ANY repeated values. That is I don't want to see anything with two elements equal like (0,0,1,2,3), (0,1,2,3,0), etc etc.

Tuples gives all possible combinations back

list = {0, 1, 2, 3, 4};
Tuples[list, 5]


I found this answer Tuples Without Replacements

But this is not I want to do.

I also tried to use Subsets and Reverse

Subsets[list, {5}]
Reverse /@ Subsets[list, {5}]


But the result of the above is to give only the $$(0,1,2,3,4)$$ and $$(4,3,2,1,0)$$.

I checked a couple of other replies here and I have not been able to find anything relevant to get me started.

• try Select[Tuples[list, 5],Length@Union@#==5&] – J42161217 Oct 13 '18 at 9:27
• or Permutations@list – J42161217 Oct 13 '18 at 9:29
• Great reply. Thanks a lot. – A_user_with_NoName Oct 13 '18 at 9:36
• I believe this question is a dupe. – J. M. will be back soon Oct 13 '18 at 10:32

lst = {a, b, s, t}

tlst = Tuples[lst, 3]

srtlst = Cases[tlst, Except[ {___, x_, ___, x_, ___}]]


Just use Permutations:

Permutations[lst]


{{a, b, s, t}, {a, b, t, s}, {a, s, b, t}, {a, s, t, b}, {a, t, b, s}, {a, t, s, b}, {b, a, s, t}, {b, a, t, s}, {b, s, a, t}, {b, s, t, a}, {b, t, a, s}, {b, t, s, a}, {s, a, b, t}, {s, a, t, b}, {s, b, a, t}, {s, b, t, a}, {s, t, a, b}, {s, t, b, a}, {t, a, b, s}, {t, a, s, b}, {t, b, a, s}, {t, b, s, a}, {t, s, a, b}, {t, s, b, a}}

If you want to restrict to 3-element sublists as in @Anxon's answer use the second argument of Permutations:

Permutations[lst], {3}]


{{a, b, s}, {a, b, t}, {a, s, b}, {a, s, t}, {a, t, b}, {a, t, s}, {b, a, s}, {b, a, t}, {b, s, a}, {b, s, t}, {b, t, a}, {b, t, s}, {s, a, b}, {s, a, t}, {s, b, a}, {s, b, t}, {s, t, a}, {s, t, b}, {t, a, b}, {t, a, s}, {t, b, a}, {t, b, s}, {t, s, a}, {t, s, b}}