Oct-15-2023, 12:22 AM
Oct-15-2023, 06:56 AM
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.