6.3.15 Rotating a list
The rotate command
rotates a list; namely it moves elements
from one side and puts them on the other.
-
rotate takes one mandatory argument and one optional
argument:
-
L, a list.
- Optionally, n, an integer (by default n=−1).
- rotate(L) returns the list formed by rotating 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 come back on
the other side. By default n=−1 and the last element becomes
the first.
Examples