In this article we will discuss different ways to remove multiple elements from list.

Suppose we have a list of numbers i.e.

Now we want to remove all the numbers from list, which are multiple of 3.

Remove multiple elements from list while Iterating

Iterate over the list and remove them one by one if its divisible by 3 i.e.

Contents of the list will be now,

Remove multiple elements from list using List Comprehension

Same thing can be achieved by List Comprehension i.e.

It will basically create a new list out of the existing list. But new list will contain the elements only which are not multiple of 3. Then replace the existing list with new one. So, it will also remove all the multiple of 3 from the list i.e.

Remove Multiple elements from list by index range using del

Suppose we want to remove multiple elements from a list by index range, then we can use del keyword i.e.

It will delete the elements in list from index1 to index2 – 1.

For example,

We have a list of int i.e.

Let’s remove elements in list from index 1 to 3 i.e.

Lists contents will be now,

Complete example is as follows,

Output:

 

 

Click Here to Subscribe for more Articles / Tutorials like this.