We can remove elements from multiple indices in a list using this syntax,
indices = index1, index2, ...
list_name = [i for j, i in enumerate(list_name) if j not in indices]
Here, we are implementing a python program to remove multiple elements from a list using list comprehension.
Example:
Input:
list1 = [10, 20, 30, 40, 50, 60, 70]
indices = 0, 2, 4
Output:
list1 = [20, 40, 60, 70]
Input:
list1 = [10, 20, 30, 40, 50, 60, 70]
indices = 1, 3
Output:
list1 = [10, 30, 50, 60, 70]
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer