In this Python list program, we will take a user input as a list and get a list after removing n elements from both sides with the help of the below-given steps.
Removing n elements from a list:
STeps to solve the program
- Take a list as input.
- Print the list after removing n elements from both sides using indexing.
- Print the result to see the output.
#Input list
list1 = [2, 5, 7, 9, 3, 4]
#Printing output
print("Remove 1 element from left", list1[1:])
print("Remove 1 element from the right", list1[:-1])
print("Remove 2 elements from left" , list1[2:])
print("Remove 2 elements from right", list1[:-2])
Output :
Remove 1 element from left [5, 7, 9, 3, 4]
Remove 1 element from the right [2, 5, 7, 9, 3]
Remove 2 elements from left [7, 9, 3, 4]
Remove 2 elements from right [2, 5, 7, 9]
Related Articles
Python program to create a dictionary with two lists.
Python program to remove the duplicate item from the list using set.
Python program to insert a sublist into the list at a specific index.
Python program to calculate the bill per fruit purchased from a given fruits list.
Python program to calculate percentage from a given mark list, the max mark for each item is 100.
Python program to get the list of all palindrome strings from the given list.