Last modified: May 23, 2026

Python List Remove by Value

Removing items from a list by value is a common task in Python. You may need to delete specific elements based on their content. This guide shows you the best methods.

We cover the remove() method. We also explore list comprehensions and loops. Each approach has its own use case.

Let's dive into practical examples. You will learn how to handle duplicates and missing values safely.

Using the remove() Method

The simplest way to remove an item by value is the remove() method. It deletes the first occurrence of the specified value.

If the value does not exist, Python raises a ValueError. Always check or handle this error.

Here is a basic example:

# Create a list of fruits
fruits = ["apple", "banana", "cherry", "banana"]
print("Original list:", fruits)

# Remove the first 'banana'
fruits.remove("banana")
print("After remove:", fruits)
Original list: ['apple', 'banana', 'cherry', 'banana']
After remove: ['apple', 'cherry', 'banana']

Notice only the first "banana" was removed. The second one remains. This is a key behavior of remove().

Removing All Occurrences with a Loop

To delete every matching value, use a loop. You can iterate over a copy of the list and remove items from the original.

Here is a safe way using a while loop:

# Remove all 'banana' values
fruits = ["apple", "banana", "cherry", "banana"]
print("Before:", fruits)

# Loop until no 'banana' remains
while "banana" in fruits:
    fruits.remove("banana")

print("After:", fruits)
Before: ['apple', 'banana', 'cherry', 'banana']
After: ['apple', 'cherry']

This method is clear but can be slow for large lists. For better performance, use a list comprehension.

Using List Comprehension to Remove by Value

List comprehension creates a new list without the unwanted values. It is efficient and elegant.

This method does not modify the original list. You assign the result back to the same variable if needed.

Example:

# Remove all 'banana' using list comprehension
fruits = ["apple", "banana", "cherry", "banana"]
print("Original:", fruits)

# Keep only items that are NOT 'banana'
fruits = [fruit for fruit in fruits if fruit != "banana"]
print("New list:", fruits)
Original: ['apple', 'banana', 'cherry', 'banana']
New list: ['apple', 'cherry']

This is the recommended way to remove all occurrences. It is fast and readable.

Removing by Value with Error Handling

When you are not sure if the value exists, use a try-except block. This prevents your program from crashing.

Example:

# Safely remove an item
colors = ["red", "green", "blue"]
target = "yellow"

try:
    colors.remove(target)
    print(f"Removed {target}")
except ValueError:
    print(f"{target} not found in list")

print("List:", colors)
yellow not found in list
List: ['red', 'green', 'blue']

This approach keeps your code robust. Always handle the ValueError when using remove().

Removing by Value with Index Check

You can also check if the value exists first using in operator. Then call remove() only if it is present.

This avoids exceptions entirely:

# Check before removing
numbers = [1, 2, 3, 4, 5]
target = 6

if target in numbers:
    numbers.remove(target)
    print(f"{target} removed")
else:
    print(f"{target} not in list")

print("Numbers:", numbers)
6 not in list
Numbers: [1, 2, 3, 4, 5]

This method is simple and readable. It is good for beginners learning Python list operations.

Removing Multiple Different Values

Sometimes you need to remove several different values from a list. Use a list comprehension with a set for fast membership testing.

Example:

# Remove multiple values at once
data = [10, 20, 30, 40, 50, 20, 30]
remove_these = {20, 30}  # Use a set for O(1) lookups

result = [item for item in data if item not in remove_these]
print("Original:", data)
print("Filtered:", result)
Original: [10, 20, 30, 40, 50, 20, 30]
Filtered: [10, 40, 50]

This technique is very efficient for large lists. It removes all specified values in one pass.

Performance Considerations

The remove() method scans the list from the beginning. Its time complexity is O(n) per call. For many removals, this can be slow.

List comprehension is O(n) overall. It is usually faster for removing all occurrences.

If you need to remove items by value frequently, consider using a different data structure. For example, a set might be more appropriate for uniqueness requirements.

Common Mistakes to Avoid

One common mistake is modifying a list while iterating over it. This can skip items or cause errors.

Bad example:

# Wrong way - modifies list during iteration
numbers = [1, 2, 2, 3]
for num in numbers:
    if num == 2:
        numbers.remove(num)
print(numbers)  # Output: [1, 2, 3] - one '2' remains!

Always iterate over a copy or use list comprehension. This avoids unexpected behavior.

Another mistake is forgetting that remove() only deletes the first match. For multiple removals, use a loop or comprehension.

Conclusion

Removing items from a Python list by value is straightforward. Use remove() for a single occurrence. Use list comprehension to delete all matches.

Always handle the ValueError when the value might be missing. This keeps your code safe and reliable.

For more advanced list tasks, check our guide on Python list functions. You can also learn about finding minimum values in lists.

Practice with these examples. You will soon master list manipulation in Python.