Python Forum

Full Version: permutations algorithm in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
for a very fast permutation algoirithm check
https://andrealbergaria.github.io/fastPe...tions.html
This does not generate all the permutations of a list, only circular permutations. They can also be generated by using the rotate() method of deque objects
>>> from collections import deque
>>> d = deque(range(6))
>>> for i in range(len(d)):
...     print(list(d))
...     d.rotate()
... 
[0, 1, 2, 3, 4, 5]
[5, 0, 1, 2, 3, 4]
[4, 5, 0, 1, 2, 3]
[3, 4, 5, 0, 1, 2]
[2, 3, 4, 5, 0, 1]
[1, 2, 3, 4, 5, 0]
To generate all the permutations, use itertools.permutations(). There are 720 permutations of 6 objects.