You can do this using while or for statements. Using for :
newList = [] for index in range(1, len(list)): newList.append(list[index]) newList.append(list[0])
Using while :
newList = [] index = 1 while index < len(list): newList.append(list[index]) index += 1 newList.append(list[0])
You can move any list to one item on the left :)
Example:
def move(list): newList = [] for index in range(1, len(list)): newList.append(list[index]) newList.append(list[0]) return newList list = [1, 2, 3, 4, 5, 'd'] list = move(list) print(list) >>>[2, 3, 4, 5, 'd', 1]
user5697845
source share