How to fix ‘ValueError: list.remove(x): x not in list’ error in Python

list.remove takes a single argument, which is the item you want to remove.

From the docs: https://docs.python.org/3/tutorial/datastructures.html

list.remove(x)
Remove the first item from the list whose value is equal to x. It raises a ValueError if there is no such item.

But "Maths, 76" is not an element in your list, hence you get the error ValueError: list.remove(x): x not in list
So you want to remove each element one at a time

Marks = ['Amy', 'Jones', 'English', 72, 'Maths', 76, 'Computer Science', 96]
Marks.remove("Maths")
Marks.remove(76)
print(Marks)

Or use a for loop

Marks = ['Amy', 'Jones', 'English', 72, 'Maths', 76, 'Computer Science', 96]

for item in ["Maths", 76]:
    Marks.remove(item)

print(Marks)

The output will be

['Amy', 'Jones', 'English', 72, 'Computer Science', 96]

Leave a Comment