Sequence operations¶
More detail on sequence types can be found on the following link:
https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range
- rotate_left(x, n)¶
Return a new list/tuple by performing left rotation on x for n steps.
INPUT:
x– listn– integer; a non-negative integer
EXAMPLES:
sage: from claasp.utils.sequence_operations import rotate_left sage: l = [1, 2, 3, 4, 5] sage: rotate_left(l, 2) [3, 4, 5, 1, 2] sage: t = (1, 1, 0, 1, 0, 1, 0) sage: rotate_left(t, 4) (0, 1, 0, 1, 1, 0, 1)
- rotate_right(x, n)¶
Return a new list/tuple by performing right rotation on x for n steps.
INPUT:
x– listn– integer; a non-negative integer
EXAMPLES:
sage: from claasp.utils.sequence_operations import rotate_right sage: l = [1, 2, 3, 4, 5] sage: rotate_right(l, 2) [4, 5, 1, 2, 3] sage: t = (1, 1, 0, 1, 0, 1, 0) sage: rotate_right(t, 4) (1, 0, 1, 0, 1, 1, 0)
- shift_left(x, n)¶
Return a new list by left shifting x for n steps.
INPUT:
x– listn– integer; an integer (0 <= n <= len(x))
EXAMPLES:
sage: from claasp.utils.sequence_operations import shift_left sage: l = [1, 2, 3, 4, 5] sage: shift_left(l, 2) [3, 4, 5, 0, 0] sage: t = (1, 1, 0, 1, 0, 1, 0) sage: shift_left(t, 4) (0, 1, 0, 0, 0, 0, 0)
- shift_right(x, n)¶
Return a new list/tuple by right shifting x for n steps.
INPUT:
x– listn– integer; an integer (0 <= n <= len(x))
EXAMPLES:
sage: from claasp.utils.sequence_operations import shift_right sage: l = [1, 2, 3, 4, 5] sage: shift_right(l, 2) [0, 0, 1, 2, 3] sage: t = (1, 1, 0, 1, 0, 1, 0) sage: shift_right(t, 4) (0, 0, 0, 0, 1, 1, 0)