Remove Multiple Elements From A List in Python
Remove Multiple Elements From A List in Python
Python
Given a list of numbers, write a Python program to remove multiple elements from a list based on
the given condition.
Example:
Input: [12, 15, 3, 10]
Output: Remove = [12, 3], New_List = [15, 10]
Multiple elements can be deleted from a list in Python, based on the knowledge we have about the
data. Like, we just know the values to be deleted or also know the indexes of those values.
Example #1: Let’s say we want to delete each element in the list which is divisible by 2 or all the
even numbers.
filter_none
edit
play_arrow
brightness_4
# Python program to remove multiple
# elements from a list
# creating a list
list1 = [11, 5, 17, 18, 23, 50]
# creating a list
list1 = [11, 5, 17, 18, 23, 50]
print(*list1)
Output:
11 5 17 23
# creating a list
list1 = [11, 5, 17, 18, 23, 50]
print(*list1)
Output:
11 50
# creating a list
list1 = [11, 5, 17, 18, 23, 50]
# items to be removed
unwanted_num = {11, 5}
# creating a list
list1 = [11, 5, 17, 18, 23, 50]