6.40.17 Shifting the elements of a list: shift
The shift command shifts the elements of a list.
-
shift takes one mandatory argument and one optional
argument:
-
L, a list.
- Optionally, n, an integer (by default n=−1).
- shift(L) returns the list formed by shifting the
elements of L n places to the left if n>0 or −n places to the right
if n<0. Elements leaving the list from one side are replaced by 0s
on the other side.
Examples.
-
Input:
shift([0,1,2,3,4])
Output:
- Input:
shift([0,1,2,3,4],2)
Output:
- Input:
shift([0,1,2,3,4],-2)
Output: