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
- Take a list as input.
- Using list comprehension, if statement and enumerate() remove certain elements from the list.
- 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
Python program to remove negative values from the list.
Python program to get a list of all elements which are divided by 3 and 7.
Python program to check whether the given list is palindrome or not.
Python Program to get a list of words which has vowels in the given string.
Python program to add 2 lists with extend method.
Python program to sort list data, with the sort and sorted method.