I would like to generate a list of all permutations of 4 digits where :
- All 4 digits are always present
- Two reversed sequences are the same solution. For example. (1,2,3,4) = (4,3,2,1)
I would like to know:
- What do you call this kind of permutations.
- If it is possible to generate this list in one step. Below there is an example that generates it in two steps.
import itertools
inp_list = range(1, 5)
# 1. Create the list of all permutations.
permutations = list(itertools.permutations(inp_list))
# 2. Remove sequences that are the reverse of another.
for _p in permutations[::-1]:
if _p[::-1] in permutations:
permutations.remove(_p)
for _p in permutations:
print("\t".join(map(str, _p)))