HOWTO · Python

How to Remove Multiple Elements From a List in Python

We can use if...else control statements, list comprehensions, list slicing and for loops to remove multiple elements from a list in Python.

On this page

To remove several items from a Python list, first decide whether the selection rule is based on each item’s value or its position. A list comprehension is useful when matching values and keeping the original list; del changes a list when removing a range or known indexes.

Choose whether to remove values or indexes

Use a condition when the items themselves determine what stays, such as keeping only even numbers. Use indexes when you know the positions to delete, regardless of the values stored there. A comprehension creates a new list, leaving the source available. del mutates the existing list, which matters when other code holds a reference to it.

Remove values that match a condition

This example keeps the even values in a new list. Change the predicate after if to match another rule, such as excluding a particular string or retaining values above a threshold.

Run this example:

numbers = [2, 3, 4, 5, 6, 7, 8]
evens = [number for number in numbers if number % 2 == 0]
print("Original:", numbers)
print("Filtered:", evens)

The original list is not modified. Avoid calling remove() on a list while looping over that same list: deleting an item shifts the remaining items, so consecutive matches can be skipped. If in-place mutation is required, iterate over a copy, for example for value in numbers.copy():, and remove matching values from numbers. For filtering, the comprehension is shorter and avoids this mutation hazard.

Delete a contiguous range with del and slicing

List indexes start at zero. In a slice start:stop, start is included and stop is excluded, so del items[2:5] deletes the items at indexes 2, 3, and 4. This changes the list itself. The same half-open rule makes adjacent ranges easy to reason about: the stop position is the first item that remains.

items = ["a", "b", "c", "d", "e", "f"]
del items[2:5]
print(items)

An omitted slice endpoint uses the beginning or end of the list. For example, del items[:2] removes the first two items, while del items[3:] removes everything from index 3 onward. These forms are useful when the range is contiguous; they do not select scattered positions.

Delete selected indexes safely

When positions are scattered, delete the indexes in descending order. Removing a higher index first leaves the lower positions unchanged. If indexes are processed from low to high, each deletion shifts later items left and changes what those indexes refer to.

items = ["a", "b", "c", "d", "e", "f"]
indexes_to_remove = [0, 2, 5]
for index in sorted(indexes_to_remove, reverse=True):
    del items[index]
print(items)

Provide valid indexes for the list as it exists before deletion, and avoid duplicates in the selection. This pattern mutates items; make a copy first if the original values must remain available. For values chosen by a condition rather than position, use filtering instead.

Choose the approach that fits your list

Choose a list comprehension to filter by value and produce a separate result. Choose del items[start:stop] to mutate the list by removing one contiguous range. For known, scattered positions, sort the indexes in descending order and delete them one by one. These methods keep the selection rule explicit and help prevent accidental changes to the wrong items.