Computer Science
Write a program that reverses a list of integers (in place).
Python
Python List Manipulation
55 Likes
Answer
l = eval(input("Enter a list: "))
print("Original list:", l)
l.reverse()
print("Reversed list:", l)
Output
Enter a list: [1, 2, 3, 4, 5]
Original list: [1, 2, 3, 4, 5]
Reversed list: [5, 4, 3, 2, 1]
Answered By
27 Likes
Related Questions
Following code prints the given list in ascending order. Modify the code so that the elements are printed in the reverse order of the result produced by the given code.
numbers = list(range(0, 51, 4)) i = 0 while i < len(numbers): print(numbers[i] , end = " ") i += 3 # gives output as : 0 12 24 36 48
Write a program to increment the elements of a list with a number.
Write a program that inputs two lists and creates a third, that contains all elements of the first followed by all elements of the second.
Ask the user to enter a list containing numbers between 1 and 12. Then replace all of the entries in the list that are greater than 10 with 10.