How to Inverse Slice in List

Everybody knows how to make a list in Python and then make a slice. If someone forgets about it, I will refer to Python List Cheat Sheet.

But what to do if it is necessary to apply inverse slice to the list, i.e. select only elements out of the slice?

Here I will show the destructive slice to the list, I mean thephysical removel of elements from the slice. If you do not need to remove these elements forever, it is better to make a deep copy of the list first.

Remve slice from the list

The idea is very simple. Make a slice of the list equal to the empty list. This will remove it.


L = [0, 1, 2, 3, 4, 5, 6]
L[1:4] = []
print(L)  # [0, 4, 5, 6]

This perfectly works for a simple slice of the list.


Published: 2026-02-24 18:10:24
Updated: 2026-02-24 18:17:37