Remove elements at Indices in List - Python
Last Updated :
24 Jun, 2025
In Python, lists store items in a specific order and each item has an index. Removing elements by index means creating a new list that excludes items at certain positions. This helps in keeping only the needed elements while discarding others based on their index.
For example:
Input : li= [5, 6, 3, 7, 8, 1, 2, 10]
idx = [2, 4, 5]
Output : [5, 6, 7, 2, 10]
Explanation: Elements at indices 2, 4, and 5 (i.e 3, 8 and 1)are removed from the list to create a new list without them.
Let’s explore different ways to remove items from specific indices.
Using del keyword
del keyword removes items from a list by specifying an index or a range (slice). It directly changes the original list.
Python
li = [10, 20, 30, 40, 50]
del li[1:4]
print(li)
Using enumerate() + list comprehension
Use enumerate() with list comprehension to loop through a list and keep only the items whose indices are not in the remove list. This creates a new list without the unwanted items in a short and clean way.
Python
li = [5, 6, 3, 7, 8, 1, 2, 10]
idx = [2, 4, 5]
res = [val for i, val in enumerate(li) if i not in idx]
print(res)
Explanation: This code checks each item’s index using enumerate(). If the index is not in the remove list, the item is added to the new list using list comprehension.
Using enumerate() + loop
Use enumerate() in a loop to get each item and its index, then skip the items at the indices you want to remove. This creates a new list with only the needed items.
Python
li = [5, 6, 3, 7, 8, 1, 2, 10]
idx = [2, 4, 5]
res = []
for i, val in enumerate(li):
if i not in idx:
res.append(val)
print(res)
Explanation: This code goes through each item in the list along with its index. If the index is not in the list of indices to remove, the item is added to a new list. This creates a new list without the unwanted elements.
Using pop()
pop() method removes an item from a list at a given index and returns its value. It updates the original list and gives you the removed element.
Python
a = [5, 6, 3, 7, 8, 1, 2, 10]
a.pop(1)
print(a)
Output[5, 3, 7, 8, 1, 2, 10]
Related Articles:
Similar Reads
Python - Remove elements at Indices in List In Python, lists store items in a specific order and each item has an index. Removing elements by index means creating a new list that excludes items at certain positions. This helps in keeping only the needed elements while discarding others based on their index. For example:Input : li= [5, 6, 3, 7
2 min read
Remove an Element from a List by Index in Python We are given a list and an index value. We have to remove an element from a list that is present at that index value in a list in Python. In this article, we will see how we can remove an element from a list by using the index value in Python. Example: Input: [1, 2, 3, 4, 5], index = 2 Output: [1, 2
3 min read
Remove last K elements of list - Python Given a list and an integer K, the task is to remove the last K elements from the list. For example, if the list is [1, 2, 3, 4, 5] and K = 2, the result should be [1, 2, 3]. Letâs explore different methods to remove the last K elements from a list in Python.Using list slicingList slicing is one of
3 min read
Python - Odd elements removal in List Due to the upcoming of Machine Learning, focus has now moved on handling the certain values than ever before, the reason behind this is that it is the essential step of data preprocessing before it is fed into further techniques to perform. Hence removal of certain values in essential and knowledge
5 min read
Python | Remove given element from list of lists The deletion of elementary elements from list has been dealt with many times, but sometimes rather than having just a one list, we have list of list where we need to perform this particular task. Having shorthands to perform this particular task can help. Let's discuss certain ways to perform this p
6 min read
Python | Remove given element from the list Given a list, write a Python program to remove the given element (list may have duplicates) from the given list. There are multiple ways we can do this task in Python. Let's see some of the Pythonic ways to do this task. Example: Input: [1, 8, 4, 9, 2] Output: [1, 8, 4, 2] Explanation: The Element 9
7 min read