Yes, it is O(1) to pop the last element of a Python list, and O(N) to pop an arbitrary element (since the whole rest of the list has to be shifted).

Here's a great article on how Python lists are stored and manipulated: An Introduction to Python Lists.

Answer from Dan Lenski on Stack Overflow
🌐
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 - # when we have to remove the first ... element of the list is N-k which will have k operations. So simply we will have O(k) average time complexity. Looking at the complexity, we should not use list to manage queue. Instead we have ...
Discussions

algorithm - Why is the big O of pop() different from pop(0) in python - Stack Overflow
Shouldn't they both be O(1), as popping an element from any location in a Python list involves destroying that list and creating one at a new memory location? 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
58
August 22, 2021
If time complexity of pop (first item) is O(n) and the time complexity for a set slice is O(k), why is my slicing function so slow?
Big O is asymptotic complexity, meaning that it's only meaningful with very large input sizes. At small inputs, countless other factors affect runtime. On top of that, even algorithms that have the same big O, they could have wildly different runtimes. You could have two algorithms that are both O(n), but one is still 100x slower than the other, it just means it will continue to be about 100x slower even as the input keeps growing and growing. TL;DR big O isn't everything: they may all be O(n), but slicing might still be slower than other options for reasons that big O ignores More on reddit.com
🌐 r/learnpython
4
2
January 12, 2025
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
People also ask

What does list.pop() do in Python?
It removes one element from the list at the given index, returns that element, and shortens the list in place; with no argument it pops the last item.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python list pop() method: remove and return items
Python List pop() Method: pop by Index, Last Item, First Item, ...
What does list.pop() return?
The value that was removed; you can assign it to a variable or use it in an expression, unlike remove() which returns None.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python list pop() method: remove and return items
Python List pop() Method: pop by Index, Last Item, First Item, ...
Why is pop(0) slow on large lists?
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.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python list pop() method: remove and return items
Python List pop() Method: pop by Index, Last Item, First Item, ...
🌐
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 - 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). So 'k' captures the idea that the time-complexity is "parameterized" not by n, but some other variable.
🌐
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 - Python list.pop(k) has a time complexity of O(n). Be cautious when use a python list as a Queue structure. Use deque instead. Always profile your code to optimize. Queue is an First-In-First-Out (FIFO) data structure.
🌐
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 ...
Find elsewhere
🌐
Runestone Academy
runestone.academy › ns › books › published › pythonds3 › AlgorithmAnalysis › Lists.html
2.6. Lists — Problem Solving with Algorithms and Data Structures 3rd edition
After thinking carefully about Table 2, you may be wondering about the two different times for pop. When pop is called on the end of the list it takes \(O(1)\), but when pop is called on the first element in the list—or anywhere in the middle it—is \(O(n)\) The reason for this lies in how Python chooses to implement lists.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › python › python list pop() method: remove and return items
Python List pop() Method: pop by Index, Last Item, First Item, and Errors (2026)
June 19, 2026 - Here n - i - 1 is n - (n - 1) - 1 = 0, so nothing slides. CPython implements that path in amortized constant time—the usual case for stack-style code. The references_moved formula is the right mental model: popping near the end touches few elements; popping near the start touches almost the whole list.
🌐
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....
🌐
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).
🌐
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.
🌐
EyeHunts
tutorial.eyehunts.com › home › python list pop first element | example code
Python list pop first element | Example code - EyeHunts
December 23, 2021 - list.pop(0) removes the first element. All remaining elements have to be shifted up one step, so that takes O(n) linear time. ... All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
🌐
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 ...
🌐
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 › if time complexity of pop (first item) is o(n) and the time complexity for a set slice is o(k), why is my slicing function so slow?
r/learnpython on Reddit: If time complexity of pop (first item) is O(n) and the time complexity for a set slice is O(k), why is my slicing function so slow?
January 12, 2025 -

Hi, I'm a beginner who has just started an introductory algorithm course. I've just finished the part on list operations and was playing around measuring runtime of each operation. I've written a function that adds consecutive numbers to the end of a list (from 1, 2, 3... to n), and other functions that remove the first or last number in that list.

Appending and popping numbers at the end of the list runs in O(1) time so it's blazing fast.

Popping the first number runs in O(n) time, so it's a bit slower.

To my surprise slicing from [1:] was extremely slow, but I thought slicing runs in O(k) time (in this case k is just n-1 so they should be similar)?

Is it the way that I've coded the function that made it slow? Is it the repeated variable assignment that slowed it down this much? Or is my time complexity analysis wrong? Thanks!

(I do realize that I'm running each list operation n times, so the time complexities of the functions are n times the time complexity of the operation, but my question remains)

import time

def add_last_num(num_list, times):
    for i in range (1, times+1):
        num_list.append(i)

def pop_last_num(num_list, times):
    for i in range (times):
        num_list.pop()

def pop_first_num(num_list, times):
    for i in range(times):
        num_list.pop(0)

def slice_first_num(num_list, times):
    for i in range(times):
        num_list = num_list[1:]
    return num_list

nums = []
n = 10**5
start = time.time()
add_last_num(nums, n)
end1 = time.time()
pop_last_num(nums, n)
end2 = time.time()
add_last_num(nums, n)
end3 = time.time()
pop_first_num(nums, n)
end4 = time.time()
add_last_num(nums, n)
end5 = time.time()
nums = slice_first_num(nums, n)
end6 = time.time()

print(f"add_last_num took {end1 - start} seconds") # runtime = 0.0015 seconds
print(f"pop_last_num took {end2 - end1} seconds") # runtime = 0.0019 seconds
print(f"pop_first_num took {end4 - end3} seconds") # runtime = 0.6272 seconds
print(f"slice_first_num took {end6 - end5} seconds") # runtime = 9.6040 seconds!!
🌐
Bradfield CS
bradfieldcs.com › algos › analysis › performance-of-python-types
Performance of Python Types
When pop is called from the end, the operation is ... O(n)O(n). Why the difference? When an item is taken from the front of a Python list, all other elements in the list are shifted one position closer to the beginning.
🌐
Iditect
iditect.com › faq › python › what-is-the-time-complexity-of-popping-elements-from-list-in-python.html
What is the time complexity of popping elements from list in Python?
In Python, popping elements from a list using the list.pop() method has a time complexity of O(n), where "n" is the number of elements that need to be shifted in the list due to the removal of the item.
🌐
Solved
code.i-harness.com › en › q › 2fc29
priority - what is the complexity of printing the first two elements of a list - Solved
list.pop(0) removes the first element. All remaining elements have to be shifted up one step, so that takes O(n) linear time. ... Difference between append vs. extend list methods in Python