Python's list implementation uses a dynamically resized C array under the hood, removing elements usually requires you to move elements following after up to prevent gaps.

list.pop() with no arguments removes the last element. Accessing that element can be done in constant time. There are no elements following so nothing needs to be shifted.

list.pop(0) removes the first element. All remaining elements have to be shifted up one step, so that takes O(n) linear time.

Answer from Martijn Pieters on Stack Overflow
🌐
Python
wiki.python.org › moin › TimeComplexity
TimeComplexity - Python Wiki
The average case for an average value of k is popping the element the middle of the list, which takes O(n/2) = O(n) operations.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › python list pop() function examples [beginners]
Python list pop() function examples [Beginners] | GoLinuxCloud
January 9, 2024 - Nevertheless, those memory allocations are infrequent, and the time complexity for the append operation is referred to as amortized O(1) time. In the following table, the timings for different operations on a list of size 10,000 are shown; you ...
🌐
Medium
medium.com › @shuangzizuobh2 › how-well-do-you-code-python-9bec36bbc322
How slow is python list.pop(0) ?. An empirical study on python list.pop… | by Hj | Medium
September 27, 2023 - Especially, should we use pop(0) to pop the oldest element from Queue? ... Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. The underlying mechanism and time complexity is nowhere mentioned. But the doc indeed advocate against using list as Queue · To implement a queue, use collection.deque which was designed to have fast appends and pops from both ends. Essentially, a Python list is implemented as an array of pointers.
🌐
Medium
medium.com › @mollihua › pop-first-element-of-a-queue-in-python-list-pop-0-vs-collections-deque-popleft-7991408e45b
Pop first element of a queue in Python — list.pop(0) vs deque.popleft() | by mollihua | Medium
July 2, 2020 - Pop first element of a queue in Python — list.pop(0) vs deque.popleft() The time complexity of deque.popleft() is O(1), while the time complexity of list.pop(0) is O(k), as index 0 is considered an …
🌐
Unstop
unstop.com › home › blog › python pop() function | list & dictionaries (+code examples)
Python pop() Function | List & Dictionaries (+Code Examples)
November 11, 2024 - Indices are zero-based, so 0 refers to the first element, 1 to the second, and so on. Negative indices can also be used to refer to elements from the end of the list, where -1 refers to the last element. The pop() function returns the value of the element that was removed from the list. If no element is removed (e.g., the list is empty), it raises an IndexError. Explore this amazing course and master all the key concepts of Python programming effortlessly!
Find elsewhere
🌐
Google Groups
groups.google.com › g › comp.lang.python › c › kiHYf5N0iz8
list.pop(0) vs. collections.dequeue
All you need to do is have each list store an offset. Initially it's 0, and pop(0) would just increment the offset. Then, all references to alist[i] would turn into array[i+offset]. Of course, that's a lot of complexity to optimize a relatively rare use case.
🌐
Finxter
blog.finxter.com › home › learn python blog › python list pop()
Python List pop() – Be on the Right Side of Change
June 19, 2021 - The popped list contains the last five elements. The original list has only one element left. The time complexity of the pop() method is constant O(1).
🌐
Quora
quora.com › What-is-the-time-complexity-of-the-pop-function-in-a-Python-list
What is the time complexity of the pop() function in a Python list? - Quora
Answer: Depends upon whether you pop from the end (which is the default when you pass no argument), or pop a specific position (which you can do, by passing an index number). Pop from the end is O(1) of course, but popping a specific position ...
🌐
Runestone Academy
runestone.academy › ns › books › published › pythonds3 › AlgorithmAnalysis › Lists.html
2.6. Lists — Problem Solving with Algorithms and Data Structures 3rd edition
Figure 3 shows the results of our experiment. You can see that as the list gets longer and longer the time it takes to pop(0) also increases while the time for pop stays very flat.
🌐
DataCamp
datacamp.com › tutorial › python-pop
How to Use the Python pop() Method | DataCamp
July 31, 2024 - When we use the pop() method to remove the first or any other element, it works in O(n) time because it involves removing an element and shifting the other elements to a new index order. Check out our Analyzing Complexity of Code through Python tutorial to learn more about time complexity in Python.
🌐
Narkive
tutor.python.narkive.com › yVyd0Dpe › why-is-list-pop-0-slow
[Tutor] why is list.pop(0) slow?
If you can tell us more details about what you're expecting to do with your lists (lots of deletes, lots of inserts, etc.), we can probably chat about efficiency issues on Python-Tutor. ... Post by Gus Tabares item = list[0] del list[0] return item It's just as slow as l.pop(0), and for the same reason. When you do "del list[0]" you reshuffle the entire list. Wari says "8 times slower", but that depends on the size of the list, the bigger the list, the bigger the time diff.
🌐
Esaezgil
esaezgil.com › home › python lists pop vs slice performance
Python lists: pop vs slice performance - Enrique Saez
February 22, 2017 - Recently I had a comment in a merge request in which I was suggested to copy the Nth-1 last elements of a list, a[1:], instead of popping its first element, pop(0). I was curious about its performance implications and decided to do some simple tests: t1 = timeit.Timer('a=50*[\'a\'];a.pop(0)') t2 = timeit.Timer('b=50*[\'b\'];b[1:]') t1.timeit(10000)/10000 6.973965995712205e-07 t2.timeit(10000)/10000 8.281046990305186e-07
🌐
Analytics Vidhya
analyticsvidhya.com › home › understanding python pop() method
Understanding Python pop() Method
October 12, 2024 - Lists in Python are over-allocated, meaning they reserve extra space to accommodate future elements without requiring immediate reallocation of memory. This minimizes the overhead of frequently resizing the list when elements are added or removed. However, removing elements with pop() decreases the size of the list, and over time, Python might decide to release unused memory, although this doesn’t happen immediately after a single pop() operation.
🌐
Codecademy Forums
discuss.codecademy.com › data science
[Beginner] What's the difference between list = list[1:] and list.pop(0)? Should lead to the same result, right? - Data Science - Codecademy Forums
December 10, 2023 - This question comes from the exercise “Delete Starting Even Numbers” in the Python 3 course for beginners, section Functions. The suggested solution uses list = list[1:] whereas I was attempting it with list.pop(0). Since both functions remove the element in the 0th index of the list, I ...