15. Problem to reverse a list with reversed and reverse methods

In this program, we will take a user input as a list and reverse a list with reversed and reverse methods with the help of the below-given steps.

Table of Contents

Reverse a list:

Method 1 : Using reversed().

Steps to solve the program
  1. Take a list as input.
  2. Reverse a list using the reversed() function.
				
					#Input list
list1 = [2,3,7,9,3,1]

#Using reversed method
print("Using reversed: ",list(reversed(list1)))

				
			

Output :

				
					Using reversed:  [1, 3, 9, 7, 3, 2]
				
			

Method 2 : Using reverse()

Steps to solve the program
  1. Take a list as input.
  2. Print the given list in reverse order using reverse().
				
					#Input list
list1 = [2,3,7,9,3,1]

#using reverse method
list1.reverse()
print("Using reverse: ", list1)
				
			

Output :

				
					Using reverse:  [1, 3, 9, 7, 3, 2]
				
			

Related Articles

list in reverse order using index slicing.

Copy the list to another list.

Leave a Comment