Remove the last N elements of a list

Solution 1:

Works for n >= 1

>>> L = [1,2,3, 4, 5]
>>> n=2
>>> del L[-n:]
>>> L
[1, 2, 3]

Solution 2:

if you wish to remove the last n elements, in other words, keep first len - n elements:

lst = lst[:len(lst)-n]

Note: This is not an in memory operation. It would create a shallow copy.