Write a program to interchange or swap the first and last number in the list
Input:
- The size of the list
- List Elements
Output:
The new list with first and last numbers exchanged
Refer sample input and output for formatting specification.
N=int(input("Enter the size of the list: ")) l1=[] print("Enter the elements: ") for i in range(N): l1.append(int(input(''))) l1[0],l1[N-1]=l1[N-1],l1[0] print('New list is:') print(l1)
Input_1:
Enter the size of the list: 5
Enter the elements:
90
80
12
25
9
Output:
New list is:
[9, 80, 12, 25, 90]
Input_2:
Enter the size of the list: 4
Enter the elements:
25
23
9
20
Output:
New list is:
[20, 23, 9, 25]
Exec. on linux
Morae!Q!
- Insert and Extend in list
- Interchange first and last number in list
- Print Odd Numbers in range
- Compare List in python
- Find whether the largest element in the array is at least twice as much as every other number in the array.
- Find minimum cost to reach the top of the floor
- Word Count in Python
- Lower case to upper case in python
- Display Time in python
- Sum of Odd And Even in Python
- Surface Area of Walls
- Find the sum of squares of individual digits
- Print the given series – 1 1 2 6 24
- Minimum number of steps required to reach destination.
- Seconds to Days Hours Minutes
- Program to remove add “Hyphen” character in the entered string
- Remove the nth Index Character from a Non-Empty String
- Relational operator Question
- Check whether all the given numbers lies in range of x and y.
- Find the Armstrong numbers between the given range.