Python Forum
permutations algorithm in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
permutations algorithm in python
#1
for a very fast permutation algoirithm check
https://andrealbergaria.github.io/fastPe...tions.html
Reply
#2
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.
buran likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020