Previous Up Next

2.37.8  Reverse a list starting from its n-th element : rotate

rotate takes as argument a list and an integer n (by default n=-1).
rotate rotates the list by n places to the left if n>0 or to the right if n<0. Elements leaving the list from one side come back on the other side. By default n=-1 and the last element becomes first.
Input :

rotate([0,1,2,3,4])

Output :

[4,0,1,2,3]

Input :

rotate([0,1,2,3,4],2)

Output :

[2,3,4,0,1]

Input :

rotate([0,1,2,3,4],-2)

Output :

[3,4,0,1,2]

Previous Up Next