I need to remove the first N elements from a list inside a function and I want the original list to be modified. What is a concise way to do this in Python?
Using a slice
isn't working because the slice operation returns a separate reference to the list. In this example, I would like pkt
to be [3,4,5]
after calling the function.
>>>> def process_packet(packet, num_bytes):
# ...
packet = packet[num_bytes:len(packet)]
print packet
>>> pkt = [1,2,3,4,5]
>>> process_packet(pkt, 2)
[3, 4, 5]
>>> print pkt
[1, 2, 3, 4, 5]