DevAcademia
C++C#CPythonJava
  • Python Fundamentals

  • Introduction to Python
  • Getting Started with Python
  • Python Syntax
  • Python Comments
  • Python Variables
  • Python Data Types
  • Python Numbers
  • Python Casting
  • Python Strings
  • Python Booleans
  • Python Operators
  • Python Lists
  • Python Tuples
  • Python Sets
  • Python Dictionaries
  • Python If...Else
  • Python Match
  • Python While Loops
  • Python For Loops
  • Python Functions
  • Python Lambda
  • Python Arrays
  • Python OOP

  • Python OOP
  • Python Constructors
  • Python Destructors
  • Python Classes/Objects
  • Python Inheritance
  • Python Polymorphism
  • Python Quiz

  • Python Fundamentals Quiz
  • Python Fundamentals

  • Introduction to Python
  • Getting Started with Python
  • Python Syntax
  • Python Comments
  • Python Variables
  • Python Data Types
  • Python Numbers
  • Python Casting
  • Python Strings
  • Python Booleans
  • Python Operators
  • Python Lists
  • Python Tuples
  • Python Sets
  • Python Dictionaries
  • Python If...Else
  • Python Match
  • Python While Loops
  • Python For Loops
  • Python Functions
  • Python Lambda
  • Python Arrays
  • Python OOP

  • Python OOP
  • Python Constructors
  • Python Destructors
  • Python Classes/Objects
  • Python Inheritance
  • Python Polymorphism
  • Python Quiz

  • Python Fundamentals Quiz

Loading Python tutorial…

Loading content
Python FundamentalsTopic 28 of 77
←PreviousPrevNextNext→

Remove List Items

Removal Methods

Python lists provide several ways to remove elements:

- **remove(value)**: Removes the first matching element

- **pop([index])**: Removes and returns the element at the given index (defaults to the last)

- **del statement**: Deletes elements by index or slice

- **clear()**: Empties the entire list

- **List comprehension**: Creates a filtered list without certain elements

Example
colors = ['red', 'green', 'blue', 'yellow', 'green']

# Remove by value
colors.remove('green')  # Removes the first 'green'

# Remove by index
popped = colors.pop(1)  # Removes 'blue'

# Delete slice
del colors[0:1]  # Removes 'red'

# Clear all
colors.clear()
print(colors)
Output
[]

Performance Considerations

MethodTime ComplexityBest For
remove()O(n)Deleting by value
pop()O(1) at end, O(n) elsewhereWhen you need the removed element
del sliceO(n)Bulk removal of ranges
clear()O(1)Resetting a list quickly
List comprehensionO(n)Conditional filtering

Advanced Removal Patterns

For more control, combine removal methods with loops, comprehensions, or slicing.

Example
# Remove all occurrences of a value
numbers = [1, 2, 3, 2, 4, 2, 5]
while 2 in numbers:
    numbers.remove(2)
print(numbers)  # [1, 3, 4, 5]

# Use list comprehension to filter
primes = [x for x in numbers if x in {2, 3, 5, 7}]
print(primes)  # [3, 5]

# Slice assignment for bulk removal
lst = [1, 2, 3, 4, 5]
lst[1:4] = []  # Removes indices 1-3
print(lst)  # [1, 5]
Output
[1, 3, 4, 5]
[3, 5]
[1, 5]
Test your knowledge: Remove List Items
Quiz Configuration
4 of 8 questions
Sequential
Previous allowed
Review enabled
Early close allowed
Estimated time: 5 min
Python FundamentalsTopic 28 of 77
←PreviousPrevNextNext→