18. Problem to print list after removing certain elements.

In this program, we will take a user input as a list & iterate all the values one by one with the python loop. Print the list after removing certain elements with the help of the below-given steps.

Removing certain elements from list:

Steps to solve the program
  1. Take a list as input.
  2. Using list comprehension, if statement and enumerate() remove certain elements from the list.
  3. Print the list after removing the elements.
				
					#Input list
list1 = [3,4,8,7,0,1,6,9]

list1 = [element for (value,element) in enumerate(list1) 
    if value not in (1,3,6)]

#Printing output
print(list1)
				
			

Output :

				
					[3, 8, 0, 1, 9]
				
			

Related Articles

common elements between lists

Remove negative elements

Leave a Comment