[Type C]Q4. Write a program that rotates the elements of a list so that the element at the first index moves to the second index, the element in the second index moves to the third index, etc, and the element in the last index moves to the first index.

Python has a set of built-in methods that you can use on strings.

split()Splits the string at the specified separator, and returns a list
len()Used to calculate the length of string

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Output:

Enter a List: 1 2 3 4 
Rotated list is:: ['4', '1', '2', '3']

A list is input from user.

The list can be right rotated by shifting its elements to a position next to them which can be accomplished by looping through the list in reverse order.

The last element of the array will become the first element of the rotated array.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-2/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page