Instagram
youtube
Facebook
Twitter

Python Program to Perform Right Rotation of List Elements by Two Positions

A Python Program to Perform Right Rotation of List Elements by Two Positions
Short Description:
This Python program performs a right rotation of the list by two positions, moving the last two elements to the front and shifting the remaining elements to the right.
Explanation (Dot Points):

• The original list is: [10, 20, 30, 40, 50, 60]
my_list[-2:] gets the last two elements[50, 60]
my_list[:-2] gets all elements except the last two[10, 20, 30, 40]
• Concatenating them gives the rotated list: [50, 60, 10, 20, 30, 40]
• The new rotated list is printed. 

Program:

my_list = [10, 20, 30, 40, 50, 60]

rotated_list = my_list[-2:] + my_list[:-2]

print("Original List:", my_list)

print("List after right rotation by 2 positions:", rotated_list)