Q. Program to swap the first half elements with the second half elements of a list of numbers.
Answer :-
lst = eval(input("Enter a list of even index:- ")) half = len(lst) // 2 print("After swapping :-") print( lst[ : half - 1 : -1 ] + lst[ : half : 1] )
Output :-
Enter a list of even index:- [1,2,3,4,5,6,7,8]
After swapping :-
[8, 7, 6, 5, 1, 2, 3, 4]
>>>
Enter a list of even index:- [2,4,6,8,10,1,3,5,7,9]
After swapping :-
[9, 7, 5, 3, 1, 2, 4, 6, 8, 10]
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )