To remove every occurrence of several values, filter the list with a comprehension:
items = [1, 2, 3, 2, 4, 5]
unwanted = {2, 4}
items = [value for value in items if value not in unwanted]
print(items) # [1, 3, 5]
This creates a new list, removes all matches, and preserves the order of the values that remain. If you mean specific positions rather than values, use index deletion instead.
Choose whether you are removing values or positions
“Remove these items” can mean either remove every element equal to certain values, or delete elements at particular indexes. The right operation depends on which you mean:
| What you know | Pattern | What it does |
|---|---|---|
| Values to exclude | [x for x in items if x not in unwanted] |
Creates a filtered list, excluding every matching occurrence. |
| A condition for keeping items | [x for x in items if keep(x)] |
Creates a list containing items for which the condition is true. |
| A contiguous range of indexes | del items[start:stop] |
Deletes the slice; the stop index is excluded. |
| A few separate indexes | Delete indexes from highest to lowest | Removes those positions without shifting the positions still to be deleted. |
| One value, first match only | items.remove(value) |
Deletes the first equal item; raises ValueError if none exists. |
| An index, and you need the deleted item | removed = items.pop(index) |
Deletes and returns that item. |
The Python tutorial documents list comprehensions, remove(), pop(), and del for items and slices in its data structures guide.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →#1 Best Overall
Remove all occurrences of one or more values
Use a comprehension with an exclusion test. To remove one value, compare each item with it:
items = ["red", "blue", "red", "green"]
items = [color for color in items if color != "red"]
print(items) # ['blue', 'green']
To exclude several values, test membership in a collection of unwanted values:
items = ["red", "blue", "red", "green", "blue"]
unwanted = {"red", "blue"}
items = [color for color in items if color not in unwanted]
print(items) # ['green']
Every matching occurrence is filtered out, including duplicates. The retained items stay in their original relative order. The comprehension returns a new list; it does not alter the original list object.
Rank #2
Keep the same list object
If other parts of your program hold a reference to the existing list and need to see the updated contents through that reference, assign the filtered result to the full slice:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallitems = [1, 2, 3, 2, 4]
reference = items
unwanted = {2, 4}
items[:] = [value for value in items if value not in unwanted]
print(reference) # [1, 3]
This replaces the contents of the existing list rather than rebinding items to a different list.
Remove items that match a condition
When the rule is more complex than membership in a set of values, express the rule as a predicate and keep only the elements that pass it:
numbers = [3, 8, 11, 14, 19]
numbers = [number for number in numbers if number % 2 != 0]
print(numbers) # [3, 11, 19]
If you already have a named predicate, filter() is another option:
def keep_odd(number):
return number % 2 != 0
numbers = list(filter(keep_odd, [3, 8, 11, 14, 19]))
In Python 3, filter() produces an iterator, so wrap it in list() when you need a list immediately. The official Functional Programming HOWTO shows filter() and a list comprehension as equivalent ways to apply a predicate. For a short condition, the comprehension makes the keep rule visible alongside the output list.
Delete by index
Delete a contiguous range
Use del with a slice when the positions are next to one another. The start is included and the stop is excluded:
items = ["a", "b", "c", "d", "e"]
del items[1:4]
print(items) # ['a', 'e']
Delete separate known indexes
When indexes refer to positions in the original list, delete them in descending order. Removing a higher index does not change the position of a lower one that remains to be removed:
items = ["a", "b", "c", "d", "e"]
indexes_to_remove = [1, 3]
for index in sorted(indexes_to_remove, reverse=True):
del items[index]
print(items) # ['a', 'c', 'e']
Deleting index 3 first leaves index 1 in place. If you delete index 1 first, the elements after it shift left, and the original index 3 no longer points to the original fourth item.
Use pop() when you need the removed item
pop(index) deletes the item at that position and returns it. It raises IndexError if the index is out of range. With no argument, pop() removes and returns the final item:
Best Value
items = ["a", "b", "c"]
removed = items.pop(1)
print(removed) # 'b'
print(items) # ['a', 'c']
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Why remove() may delete only one item
items.remove(value) removes only the first item equal to value. Calling it once does not remove duplicates, and it raises ValueError if the value is absent. For example:
items = [2, 1, 2, 3]
items.remove(2)
print(items) # [1, 2, 3]
Use a comprehension such as [x for x in items if x != 2] when you want to remove every occurrence.
Avoid deleting from the list you are iterating over
Deleting an element shifts later elements left. If you iterate forward over the same list while deleting from it, the next element can move into the position just visited and be skipped. A comprehension avoids that mutation-while-iterating problem by building the filtered result rather than deleting entries during the traversal:
items = [1, 2, 2, 3, 2]
items = [value for value in items if value != 2]
print(items) # [1, 3]
Performance considerations
A comprehension checks the input items and constructs a result list. Repeated in-place deletions can shift later elements, but there is no universal timing claim that applies to every list size, Python implementation, or deletion pattern. If performance is important, benchmark with the actual data, runtime, and distribution of items to remove.
Recommended Free Tools
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




