Informatics Practices
WAP to shift elements of a list so that first element moves to the second index and second index moves to the third index, etc., and last element shifts to the first position.
Suppose list is [10, 20, 30, 40]
After shifting it should look like: [40, 10, 20, 30]
Python List Manipulation
6 Likes
Answer
l = eval(input("Enter the list: "))
print("Original List")
print(l)
l = l[-1:] + l[:-1]
print("Rotated List")
print(l)Output
Enter the list: [10, 20, 30, 40]
Original List
[10, 20, 30, 40]
Rotated List
[40, 10, 20, 30]
Answered By
3 Likes
Related Questions
Write a program to multiply an element by 2 if it is an odd index for a given list containing both numbers and strings.
Write a program to count the frequency of a given element in a list of numbers.
An array Num contains the following elements:
3, 25, 13, 6, 35, 8, 14, 45
Write a function to swap the content with next value divisible by 5 so that the resultant array looks like:
25, 3, 13, 35, 6, 8, 45, 14
The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) is stored in the following list:
studRecord = ['Rinku', 'A-36', [56, 98, 99, 72, 69], 78.8]Write Python statements to retrieve the following information from the list studRecord.
(a) Percentage of the student
(b) Marks in the fifth subject
(c) Maximum marks of the student
(d) Roll No. of the student
(e) Change the name of the student from 'Rinku' to 'Rajat'