Technical skill practice
Python List remove(): Delete the First Matching Value
Python list.remove(value) deletes the first list item equal to the requested value. It mutates the list and returns None. It is a value search, unlike pop, whose optional argument is a position. A missing value raises ValueError.
Start with a small, explicit task
A fictional guest list contains the same display name twice. Remove one matching name and inspect what remains. Then compare that result with a new list that excludes every matching name. Display names are intentionally not unique IDs, which makes duplicate behavior visible.
Run the complete example
This original example was checked with Python 3.12.14. Save it as python_list_remove.py and run it with Python 3.12. It uses only the standard library. The assertions check the stated results.
Expected output
['Omar', 'Mina', 'Tess']
['Omar', 'Tess']
missing guest rejected
guests = ["Mina", "Omar", "Mina", "Tess"]
returned = guests.remove("Mina")
assert returned is None
assert guests == ["Omar", "Mina", "Tess"]
remaining = [guest for guest in guests if guest != "Mina"]
assert remaining == ["Omar", "Tess"]
try:
guests.remove("Rae")
except ValueError:
result = "missing guest rejected"
else:
raise AssertionError("expected missing-value failure")
assert guests == ["Omar", "Mina", "Tess"]
print(guests)
print(remaining)
print(result)
Explain the result
Only the first Mina disappears from guests; the later equal name stays. The returned None is not the updated guest list. The comprehension then creates a separate list without any remaining Mina entry, illustrating a different task: remove every matching value rather than one occurrence.
The failed removal of Rae does not change guests. Catching ValueError is deliberate here because the missing-value case is the one being demonstrated. In a real guest system, equal display names may represent different people; an identity-aware record is needed before deciding which actual guest to remove.
Avoid these mistakes
Do not write guests = guests.remove(name), which assigns None after mutation. Avoid repeatedly removing from the same list while iterating over it unless you have carefully designed the traversal; a separate filtered output often makes an all-matches rule easier to inspect.
Questions, answered
Does remove delete every duplicate?
No. The checked result keeps the second Mina. Use a separate rule when every equal value should be excluded.
How do I remove by index?
Use list.pop(index) if you need the removed value, or an appropriate indexed deletion; remove expects a value.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.