Hi Y'all.
I have recently purchased a book so I can teach my-self python. I'm just stick on one of the quizzes and need some guidance if possible. The question is :
Can you create a list l that prints [[1,2,3],[1,2,3]] but when I rotate only the first part by rotateRx(l[1]) and then print l it turns out that both parts have been rotated, i.e I get [[3,1,2],[3,1,2]].
I have tried to reproduce the output but only been able to rotate the second half. A bit baffled how you would rotate both. Any help would be appreciated.
My solution:
I have recently purchased a book so I can teach my-self python. I'm just stick on one of the quizzes and need some guidance if possible. The question is :
Can you create a list l that prints [[1,2,3],[1,2,3]] but when I rotate only the first part by rotateRx(l[1]) and then print l it turns out that both parts have been rotated, i.e I get [[3,1,2],[3,1,2]].
I have tried to reproduce the output but only been able to rotate the second half. A bit baffled how you would rotate both. Any help would be appreciated.
My solution:
l=[[1,2,3],[1,2,3]] def rotateRx4(alist): alist[0],alist[1],alist[2]=alist[-1],alist[0],alist[1] rotateRx4(l[1]) print(l)