filmov
tv
Code 68: Python program to right rotate the elements of an array | 365 days of Code

Показать описание
Here is the program to right rotate the elements of an array using Python.
Code -
num_list = [1,2,3,4,5]
r = 1 # Number of times to rotate
print(num_list)
for i in range(r):
last = num_list[-1]
for j in range(len(num_list) -1, 0, -1):
num_list[j] = num_list[j - 1]
num_list[0] = last
print(num_list)
Code -
num_list = [1,2,3,4,5]
r = 1 # Number of times to rotate
print(num_list)
for i in range(r):
last = num_list[-1]
for j in range(len(num_list) -1, 0, -1):
num_list[j] = num_list[j - 1]
num_list[0] = last
print(num_list)