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
Note that there is a fast-path ... complexity, but it can significantly affect the constant factors: how quickly a typical program finishes. [1] = These operations rely on the "Amortized" part of "Amortized Worst Case". Individual actions may take surprisingly long, depending on the history of the container. [2] = Popping the intermediate ...
Discussions

What is the time complexity of popping elements from list in Python? - Stack Overflow
I wonder what the time complexity of the pop method of list objects is in Python (in CPython particulary). Also does the value of N for list.pop(N) affect the complexity? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is popleft() faster than pop(0) ?

Yes. list.pop(0) is O(n), and deque.popleft() is O(1).

More on reddit.com
๐ŸŒ r/learnpython
9
6
May 14, 2020
Does pop(i) have a Time Complexity of O(n) or O(k)?
I'm reading a book on data structures and algorithms in python and the say pop(i) is O(n) but on Python's website it states that pop intermediate isโ€ฆ More on reddit.com
๐ŸŒ r/learnpython
3
3
July 1, 2020
What is the time complexity of pop() for the set in Python? - Stack Overflow
I know that pop the last element of the list takes O(1). And after reading this post What is the time complexity of popping elements from list in Python? I notice that if we pop an arbitrary number... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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 - 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.
๐ŸŒ
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 ...
๐ŸŒ
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).
Find elsewhere
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ python pop() function | list & dictionaries (+code examples)
Python pop() Function | List & Dictionaries (+Code Examples)
November 11, 2024 - From the End:Python pop() is highly efficient (O(1) time complexity) when removing elements from the end of a list.
๐ŸŒ
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 - The time complexity depends not on n, but on the index value to list.pop(), which is possibly a function of n, or not. For example, as n grows, any fixed negative index value to list.pop() will be O(1), and any fixed non-negative value will be O(n).
๐ŸŒ
Medium
thinklikeacto.medium.com โ€บ time-complexity-of-popping-elements-from-list-in-python-215ad3d9c048
Time complexity of popping elements from list in Python! | by Naresh Thakur | Medium
January 23, 2020 - 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)
๐ŸŒ
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.
๐ŸŒ
UCI
ics.uci.edu โ€บ ~pattis โ€บ ICS-33 โ€บ lectures โ€บ complexitypython.txt
The Complexity of Python Operators/Functions
The operations are organized by increasing complexity class Lists: Complexity Operation | Example | Class | Notes --------------+--------------+---------------+------------------------------- Index | l[i] | O(1) | Store | l[i] = 0 | O(1) | Length | len(l) | O(1) | Append | l.append(5) | O(1) | mostly: ICS-46 covers details Pop | l.pop() | O(1) | same as l.pop(-1), popping at end Clear | l.clear() | O(1) | similar to l = [] Slice | l[a:b] | O(b-a) | l[1:5]:O(l)/l[:]:O(len(l)-0)=O(N) Extend | l.extend(...)| O(len(...)) | depends only on len of extension Construction | list(...) | O(len(...)) | depends on length of ...
๐ŸŒ
Scribd
scribd.com โ€บ doc โ€บ 132591380 โ€บ python-list
Python List Operations Time Complexity | PDF
The document compares the time ... pop() operations have constant time complexity, while insert(0,1) and pop(0) have linear time complexity, as insert(0,1) and ......
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ time-complexities
Python Big O: the time complexities of different data structures in Python - Python Morsels
April 16, 2024 - That's what Python's collections.deque data structure is for. >>> from collections import deque >>> queue = deque([2, 1, 3, 4]) Here are the time complexities of common deque operations: Note that we can efficiently add and remove items from the beginning of a deque with the appendleft and popleft methods. If you find yourself calling the insert or pop methods on a list with an index of 0...
๐ŸŒ
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.
๐ŸŒ
Google Groups
groups.google.com โ€บ g โ€บ comp.lang.python โ€บ c โ€บ kiHYf5N0iz8
list.pop(0) vs. collections.dequeue
But, anyway, if 'list' already uses a doubling buffer then the only overhead from the pop optimization would, AFAICS, be a single add in every indexing. On the third & gripping hand, however, a proof-of-concept actual implementation (patch) would be needed to ensure that one doesn't overlook any showstopper or serious problem, and to provide timings. And the special case would have to be documented as a special case. Hm, it would be nice if the Python docs offered complexity (time) guarantees in general...
๐ŸŒ
Bradfield CS
bradfieldcs.com โ€บ algos โ€บ analysis โ€บ performance-of-python-types
Performance of Python Types
However, the expansion rate is cleverly chosen to be three times the previous size of the array; when we spread the expansion cost over each additional append afforded by this extra space, the cost per append is ... O(1)O(1) on an amortized basis. ... Popping from a Python list is typically performed from the end but, by passing an index, you can pop from a specific position.