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 …
Discussions

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
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
python - What are effects on overhead of using list.pop(0)? - Stack Overflow
If the list is large and you do a lot of pop(0), perhaps reversing it and doing pop() from the end would make sense. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... New site design and philosophy for Stack Overflow: Starting February 24, 2026... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... 84 What is the time complexity of popping elements from list in Python... More on stackoverflow.com
🌐 stackoverflow.com
I was surprised at how slow list.pop() is! And list.remove() is even many times slower
This is simply how lists work, nothing surprising here. Removing the first element requires moving all the elements after it one step to the left to fill that gap, which makes this operation run in linear time. It means that clearing the list this way is O(n2), so it unsurprisingly takes a long time, as bubble sorting the (shuffled) list could even be faster. This is why we think of alternatives when solving problems, such as using collections.deque, reversing the list (O(n) instead of O(n2)) or just using pop() from the end if it works. More on reddit.com
🌐 r/learnpython
38
57
August 22, 2021
🌐
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. what is the time complexity of accessing an item in a list
🌐
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.
🌐
Medium
medium.com › @mollihua › pop-first-element-of-a-queue-in-python-list-pop-0-vs-collections-deque-popleft-7991408e45b
list.pop(0) vs deque.popleft() | by mollihua
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 …
🌐
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).
🌐
Python
wiki.python.org › moin › TimeComplexity
TimeComplexity - Python Wiki
n - k elements have to be moved, ... 1 moves. 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....
Find elsewhere
🌐
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)
🌐
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 ...
Top answer
1 of 2
6

If you look into the actual pop code in cpython/Objects/listobject.c, you'll see there are memcpy/memmove calls for the case where you're not popping the last element (it's actually done in the call to list_ass_slice).

Hence, it's not a non-trivial expense (certainly not O(1) as suggested in a comment - that may be true for a linked-list type structure but that's not what Python lists are). It's the fact that it's doing the element removal in-place that means that the id won't change but that doesn't mean it's efficient.

For example, consider the list:

    0    1     2     3     4     5     <- index
+-----+-----+-----+-----+-----+-----+
|  A  |  B  |  C  |  D  |  E  |  F  |
+-----+-----+-----+-----+-----+-----+

Popping the last element is usually an O(1) operation since it simply needs to take out F and reduce the size.

However, popping the first element means taking out A and then moving all the elements B..F to the position where A was:

    0    1     2     3     4     <- index
+-----+-----+-----+-----+-----+
|  B  |  C  |  D  |  E  |  F  |
+-----+-----+-----+-----+-----+

But keep in mind it probably won't matter unless your lists get really big. The objects themselves aren't being reconstructed since the list only holds references to them.

2 of 2
0

The list has a buffer that holds references to its values. After pop(0), the remaining references need to be copied down one in this buffer. If you happen to pass certain thresholds a smaller buffer will be allocated and the references will be copied there.

Unless the list is large, it doesn't make much of a difference. If the list is large and you do a lot of pop(0), perhaps reversing it and doing pop() from the end would make sense.

🌐
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.
🌐
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 ·
🌐
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.
🌐
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).
🌐
Reddit
reddit.com › r/learnpython › i was surprised at how slow list.pop() is! and list.remove() is even many times slower
r/learnpython on Reddit: I was surprised at how slow list.pop() is! And list.remove() is even many times slower
August 22, 2021 -

I know there is a list.clear(), I'm just sharing that I didn't expect that using list.pop() and list.remove() specifically could slow down the program that much.

li = list(range(500000))

Creating a list is quick.

So we are going to test out pop/remove specific values. For the purpose of this "benchmark", we are going to remove all elements from the list:

while (li):
    li.pop(0)

It took 74.735 seconds to pop all the elements! It's ridiculously long.
I KNOW it would have been much faster if I even had used li.pop() without the index or maybe used filter function, list comprehension with conditional or whatever
But that's what I'm trying to show, how slow it is to remove certain list items specifically using pop and remove methods.

And li.remove(), which always requires a specified value to remove, is even worse than pop!

 for num in li:
    li.remove(num)

This one took me 303.268 seconds to complete. How crazy it is.

I've been having fun with abstract data structures. Implemented linked lists and a queues running on linked lists.

And for the sake of interest, I decided to compare the performance of the queue based on the linked list and the usual python list. And I was surprised. When my linked list Queue dequeued 500.000 elements in 0.5 seconds, while python list Queue was doing it in 75 seconds.

Top answer
1 of 5
46
This is simply how lists work, nothing surprising here. Removing the first element requires moving all the elements after it one step to the left to fill that gap, which makes this operation run in linear time. It means that clearing the list this way is O(n2), so it unsurprisingly takes a long time, as bubble sorting the (shuffled) list could even be faster. This is why we think of alternatives when solving problems, such as using collections.deque, reversing the list (O(n) instead of O(n2)) or just using pop() from the end if it works.
2 of 5
13
Just thought I'd mention that, on top of being the slowest option presented here, for num in li: li.remove(num) is also broken; it skips every other value in the list and the result is essentially only half of the original list, not an empty one. The reason for this already came up in the other answers, as the values shift in the list when you remove one, but the loop itself doesn't take this into account. You can think of the loop as if it had a hidden index variable it updates on every iteration, and when the values are shifted what was previously going to be the next value after deletion is now where the deleted one was, the loop index goes up by one, and the next index to be removed is the one next to the current one. EDIT: It's easier to understand visually, I guess. idx | 0 | 1 | 2 | 3 | 4 | val | 1 | 2 | 3 | 4 | 5 Loop index: 0 Removing item at index 0 idx | 0 | 1 | 2 | 3 | 4 | val | 2 | 3 | 4 | 5 | ... Loop index: 1 Removing item at index 1 idx | 0 | 1 | 2 | 3 | 4 | val | 2 | 4 | 5 | ... | ... Loop index: 2 Removing item at index 2 Idx | 0 | 1 | 2 | 3 | 4 | val | 2 | 4 | ... | ... | ... EDIT #2: If you needed to empty a list in a real project, the best options would be to either reassign an empty list, or use list.clear which is way faster than using list.pop in a loop.
🌐
DEV Community
dev.to › wnleao › python-deque-vs-list-time-comparison-5ch4
Python deque vs list: a time comparison - DEV Community
April 10, 2022 - Notice that dq.appendleft(42) is ... to removing elements from the start. timeit(lambda: ls.pop(0), number=tnumber) # 1.1129129020000619 secs...
🌐
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.