Revese the elements in list python

Python Program to get list size n and n elements of list, then reverse the n elements.

Sample Input 1:

5 5 7 9 3 1

Sample Output 1:

1 3 9 7 5

Program or Solution

				
			
					
			
				
			

Program Explanation

initialize start to first location of list and stop to last location of list using start=0 stop=len(l)-1 swap the elements in location start and stop, then increment start by 1 and decrement stop by 1.

l[start],l[stop]=l[stop],l[start] repeat the above step till start is less than stop


Tech Events

Hackathon