Write a program to rotate and print elements of a list


Topic: Write a program to rotate and print elements of a list

Solution

arr = [1, 2, 3, 4, 5];     
  
n = 3;      
  
for i in range(0, n):    
    #Stores the last element of array    
    last = arr[len(arr)-1];    
        
    for j in range(len(arr)-1, -1, -1):    
        #Shift element of array by one    
        arr[j] = arr[j-1];    
            
       
    arr[0] = last; 
    
print(arr)
   



List all Python Programs