This is related to question How to generate all permutations of a list in Python
How to generate all permutations that match following criteria: if
itertools.permutations does exactly what you want. you might make of use of reversed built-in as well