Reverse the first half of list elements in python
Python Program to get list size n and n elements of list, then reverse the first n/2 elements.
Sample Input 1:
5 5 7 9 3 1
Sample Output 1:
7 5 9 3 1
Program or Solution
l=list(map(int,input("Enter Numbers:").split())) start=0 stop=len(l)//2 -1 while(start<stop): l[start],l[stop]=l[stop],l[start] start+=1 stop-=1 print(l)
initialize start to first location of list and stop to last location of list using start=0 stop=len(l)/2-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
- list input in python
- sum of list in python | without using built-in function
- Average of list in python | without using built-in function
- linear search in python
- largest element in the list python | without using built-in function
- smallest element in the list python | without using built-in function
- Print all the numbers which are less than given key element from a given list.
- delete element in list python
- Revese the elements in list python
- Reverse the second half of list elements in python
- list sort python
- list sort descending order python
- Python Program to sort half of the list elements in ascending order and next half in descending order.
- merging two lists in python
- Python Program to replace every element with the greatest element on right side
- circular list rotation in python