So I encountered a problem of permutations with fixed previous element in list. So, I have list, which is an ordered sequence of numbers from 1 till n.
EDIT
here's a reformuliration of my question: Can you imagine a tree graph? So, 1st level - it's a top (also known as parent) vertex. So, if we have vertex like [1, 2, 3, 4], our next step would be to make permutations, inserting all numbers in the position n, it means that in output we would have this:
1.1 lvl [1, 2, 3, 4]
2.1 lvl [1, 2, 4, 3]
3.1 lvl [1, 3, 4, 2]
4.1 lvl [2, 3, 4, 1]
So, then we look at level 1.1 and make permutations of n-1th element ( 4 is fixed and do not take part in permutation on this level). Output would be:
1.1.1 lvl [1, 2, 3, 4]
1.1.2 lvl [1, 3, 2, 4]
1.1.3 lvl [2, 3, 1, 4]
The we took 1.1.1 lvl and fix n-2 element (as you can see there is no point to fix 1st element). So, on this level we have fixed 3, and 4, which is n-1th and nth elemets, outut is:
1.1.1.1 lvl [1, 2, 3, 4]
1.1.1.2 lvl [2, 1, 3, 4]
We have dinished here, but do not have finish yet. Go on lvl up ( it's level 1.1.2). And permutate it. Here we have fixed n-1th element (it's 2) and nth (it's 4)
1.1.2.1 lvl [1, 3, 2, 4]
1.1.2.2 lvl [3, 1, 2, 4]
Finished here. GOTO on upper level. Here fixed 1 and 4. So,
1.1.3.1 lvl [2, 3, 1, 4]
1.1.3.2 lvl [3, 2, 1, 4]
We have finished the level 1.1 and going to 2.1, where we repeat the same procedure.
So, the question is: how to do this in python?
itertools.permutationsgives you a proper hint as to how to approach the problem. It won't give you the answer in the exact format you want, but every order of Permutohedron is the same as taking the permutation (n!). Since this is an academic exercise, it's wise to take what information you've received and attempt to apply it to your problem.