I have a list in the form of [2, 1, 4, 3].
Is there a way to produce all of the possible sequences of the list values while keeping the same order? To further clarify, I am expecting something like this:
[1, 4, 3, 2],
[4, 3, 2, 1],
[3, 2, 1, 4],
[2, 1, 4, 3]
>Solution :
>>> data = [4, 3, 2, 1]
[4, 3, 2, 1]
>>> l = len(data)
>>> for i in range(l):
... print(data[l - i:] + data[0:l - i])
...
[4, 3, 2, 1]
[1, 4, 3, 2]
[2, 1, 4, 3]
[3, 2, 1, 4]
Or if we want to capture them rather than print them:
[data[len(data)-i:] + data[0:len(data)-i] for i in range(len(data))]