Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

rotate list python

# rotate left with slicing

def rotate_list_left(lst, rotation_value):

    result_list =lst[rotation_value:]+lst[:rotation_value]
    print(result_list)

rotate_list_left([1,2,3,4,5,6],1)
rotate_list_left([1,2,3,4,5,6],2)

# rotate left with for loop

def rotate_list_left(_list : list, rotation_value: int):

    result_list = _list.copy()

    for k in range(0, len(_list)):
        result_list[k-rotation_value] = _list[k]
    print(result_list)

rotate_list_left([1,2,3,4,5,6],1)
rotate_list_left([1,2,3,4,5,6],2)
 
PREVIOUS NEXT
Tagged: #rotate #list #python
ADD COMMENT
Topic
Name
9+4 =