I am trying to use a simple s list del a[0]to simulate deque.popleft(). I just want to understand how it works delin Python. For instance:
a = [0,1,2,3,4,5]
ais in continuous space in memory. After I call del a[0], Python will allocate a new space and copy there 1,2,3,4,5, or it will just give a anew address (which matches a = a[1:]).
If it allocates a new space, does this mean that it del a[0]is an operation _O (len (a) _)?
If del a[0]matches a = a[1:], will Python free up memory space removed from the array?
source
share