-1

When removing an element from the front of a list in python by doing list.pop(0). Will this create a new array or just move the pointer to the new first element. And if not what are the reasons for not doing so?

PKuhn
  • 1,338
  • 1
  • 14
  • 30

1 Answers1

4

Will this create a new array or just move the pointer to the new first element.

Neither. It shifts all remaining list elements to fill the gap. While it could be implemented by changing the pointer to the first element, doing so would introduce additional time and space overhead for other operations. If you need efficient insertion and removal at both ends of a sequence, collections.deque does that job.

user2357112
  • 260,549
  • 28
  • 431
  • 505