Python How to remove multiple elements from list ?
Description:
To remove multiple element at a time we can make use of another list which includes unwanted elements from the main list and using that list we can remove multiple element at a time.
Program:
item = [23, 15, 12, 18, 3, 20]
# items to be removed
Item_to_remove= {18, 15,23}
New_Item= [i for i in item if i notin Item_to_remove]
# printing modified list
print("New list after removing unwanted numbers: ", New_Item)
Output:
New list after removing unwanted numbers: [12, 3, 20]
Comments