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
🌐
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 - How slow is python list.pop(0) ? An empirical study on python list.pop complexity TL;DR Python list.pop(k) has a time complexity of O(n). Be cautious when use a python list as a Queue structure. Use …
🌐
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 …
🌐
Reddit
reddit.com › r/learnpython › does pop(i) have a time complexity of o(n) or o(k)?
r/learnpython on Reddit: Does pop(i) have a Time Complexity of O(n) or O(k)?
July 1, 2020 - If you pop the last element it is O(1), if you pop the first element it is O(n). So yes, your understand seems correct. Big O Cheat Sheet: the time complexities of operations Python's data structures
🌐
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.
🌐
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).
🌐
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.
Find elsewhere
🌐
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 is O(n) because the list elements are then shifted to ...
🌐
Esaezgil
esaezgil.com › home › python lists pop vs slice performance
Python lists: pop vs slice performance - Enrique Saez
February 22, 2017 - t1 = timeit.Timer('a=50000*[\'a\'];a.pop(0)') t2 = timeit.Timer('b=50000*[\'b\'];b[1:]') t1.timeit(10000)/10000 0.0002497872758001904 t2.timeit(10000)/10000 0.00044558706480020194 · shows that slicing the list carries a performance penalty of ~50% compared to just doing a pop of the first element. This penalty seems to plateau after a certain list size. Time complexity in the Python wiki ·
🌐
Medium
medium.com › @thakurinbox › time-complexity-of-popping-elements-from-list-in-python-215ad3d9c048
Time complexity of popping elements from list in Python! | by Naresh Thakur | Medium
December 13, 2021 - If we do a.pop(k)first remove and return the k'th and then moves all the elements after k one position up. So that we do not have null/empty/void value at k’th position. So what will be the time complexity when we pass an argument? Consider the length of list is N and we need to remove an element at k position as follows. ... # when we have to remove the first element O(N)# if we consider list we have above a = [1, 2, 3, 4, 5, 6] O(6-0) = O(6) = O(N)
🌐
CodeSignal
codesignal.com › learn › courses › linked-lists-stacks-and-queues-in-python › lessons › understanding-and-implementing-queues-exploring-core-concepts-python-implementation-and-time-complexity
Understanding and Implementing Queues: Exploring Core ...
In Python, we can implement Queues using built-in data types. Indeed, the Python list datatype comes in handy here. Python lists, however, have a significant drawback: the pop(0) method has · O · ( n · ) O(n)O(n) time complexity, while we would like it to be ·
🌐
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.
🌐
Bomberbot
bomberbot.com › python › python-pop-how-to-pop-from-a-list-or-an-array-in-python
Python .pop() – How to Pop from a List or an Array in Python - Bomberbot
When discussing the performance of an operation like pop(), we need to consider its time and space complexity using Big O notation.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › python list pop() method: remove and return items
Python List pop() Method: pop by Index, Last Item, First Item, and Errors (2026)
January 9, 2024 - Removing index 0 shifts every remaining element one slot left, so cost grows with list length; popping the end is cheap because no shift is needed. ... Computer Science graduate from the University of Central Asia, currently employed as a full-time Machine Learning Engineer at uExel.
🌐
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.
🌐
UCI
ics.uci.edu › ~pattis › ICS-33 › lectures › complexitypython.txt
The Complexity of Python Operators/Functions
iterable check ==, != | l1 == l2 | O(N) | Insert | l[a:b] = ... | O(N) | Delete | del l[i] | O(N) | depends on i; O(N) in worst case Containment | x in/not in l| O(N) | linearly searches list Copy | l.copy() | O(N) | Same as l[:] which is O(N) Remove | l.remove(...)| O(N) | Pop | l.pop(i) | O(N) | O(N-i): l.pop(0):O(N) (see above) Extreme value | min(l)/max(l)| O(N) | linearly searches list for value Reverse | l.reverse() | O(N) | Iteration | for v in l: | O(N) | Worst: no return/break in loop Sort | l.sort() | O(N Log N) | key/reverse mostly doesn't change Multiply | k*l | O(k N) | 5*l is O(N): len(l)*l is O(N**2) Tuples support all operations that do not mutate the data structure (and they have the same complexity classes).