Here is one way. It uses slices to choose various parts of the list then put them back together in a different way. This moves the first element of the list through various positions in the list. Note that this code could be sped up slightly, at the cost of an additional line of code, by calculating and storing a[:1]
before the loop, since that does not change between executions of the loop. You should also note that Python's list does not have a rotate
method, so I am not sure just what you were trying.
a =[0, 1, 2, 3]
for i in range(len(a)):
print(a[1:i+1] + a[:1] + a[i+1:])
The printout from that is what you want, though with a space after each comma, as is standard in Python.
[0, 1, 2, 3]
[1, 0, 2, 3]
[1, 2, 0, 3]
[1, 2, 3, 0]
If you really want no spaces in the output, you could use
a =[0, 1, 2, 3]
for i in range(len(a)):
print(str(a[1:i+1] + a[:1] + a[i+1:]).replace(' ', ''))
which gives the output
[0,1,2,3]
[1,0,2,3]
[1,2,0,3]
[1,2,3,0]