rotate¶
-
support.lists.
rotate
(List, first_value, direction='l', last_value=None, other_lists=[])¶ Rotate one or more lists subject to constraints on the first list
‘last_value’ is useful if there are multiple instances of ‘first_value’. This is dangerous because a list might not have a last value equal to ‘last_value’ when the first value is ‘first_value’.
The lists in ‘other_lists’ must have the same length as List.
Examples:
In [2]: l = [1, 3, 2, 8, 6, 0, 7, 5, 4] In [3]: rotate(l,"l",8) Out[3]: [8, 6, 0, 7, 5, 4, 1, 3, 2] In [4]: rotate(l,"r",1) Out[4]: [1, 3, 2, 8, 6, 0, 7, 5, 4] In [5]: l = [1,1,0,0,0,2,2,2,1] In [6]: rotate(l,'l',0,1) Out[6]: [0, 0, 0, 2, 2, 2, 1, 1, 1] In [7]: rotate(l,'r',1,2) Out[7]: [1, 1, 1, 0, 0, 0, 2, 2, 2] In [8]: l = [1, 3, 2, 8, 6, 0, 7, 5, 4] In [9]: ll = ['a','b','c','d','e','f','g','h','i'] In [10]: rotate(l, 8, 'l', other_lists=[ll]) Out[10]: [[8, 6, 0, 7, 5, 4, 1, 3, 2], ['d', 'e', 'f', 'g', 'h', 'i', 'a', 'b', 'c']]
:param List : list to rotate and test for constraint compliance :type List : list of any type
:param first_value : value which must be first in the new list :type first_value : same type as entries of List
:param direction : left or right :type direction : str
:param last_value : value which must be last if ‘first_value’ is satisfied :type last_value : same type as entries of List
:param other_lists :