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
🌐
GeeksforGeeks
geeksforgeeks.org › python › queue-in-python
Queue in Python - GeeksforGeeks
December 11, 2025 - Python · q = [] q.append('a') q.append('b') q.append('c') print("Initial queue:", q) print("Elements dequeued from queue:") print(q.pop(0)) print(q.pop(0)) print(q.pop(0)) print("Queue after removing elements:", q) Output · Initial queue: ['a', 'b', 'c'] Elements dequeued from queue: a b c Queue after removing elements: [] Explanation: We added elements using append() and removed from the front using pop(0).
🌐
W3Schools
w3schools.com › python › python_dsa_queues.asp
Queues with Python
Using a Python list as a queue: queue = [] # Enqueue queue.append('A') queue.append('B') queue.append('C') print("Queue: ", queue) # Peek frontElement = queue[0] print("Peek: ", frontElement) # Dequeue poppedElement = queue.pop(0) print("Dequeue: ", poppedElement) print("Queue after Dequeue: ", queue) # isEmpty isEmpty = not bool(queue) print("isEmpty: ", isEmpty) # Size print("Size: ", len(queue)) Try it Yourself » ·
🌐
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 - line 19: queue = list([root]) line 21: cur = queue.pop(0) and here is the profiling results. The list.pop(0) operation is almost 1000 times slower than deque.popleft. Consequently, the whole program finishes with twice the time. This is the difference between O(1) time complexity function v.s. O(n) one. Python list.pop(0) is extremely slow for a large list.
🌐
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 - def listpop(alist): ts = time.time() alist.pop(0) te = time.time() print("{:e}".format(te - ts))def dequepopleft(alist): q = collections.deque(alist) ts = time.time() q.popleft() te = time.time() print("{:e} seconds".format(te - ts))a = [x for x in range(10**6)]listpop(a) # output: 4.558802e-03 seconds dequepopleft(a) # output: 2.861023e-06 seconds · Python · Queue ·
🌐
Reddit
reddit.com › r/learnpython › best way to continuously pop elements from a queue until condition is reached
r/learnpython on Reddit: Best way to continuously pop elements from a queue until condition is reached
April 23, 2024 -

I have a deque that consists of datetime objects (the rightmost elements will always be newer) and I'm trying to write some logic to pop items older than n seconds off the queue. I have it sort of functioning, but my while loop depends on looking at the -1 element of the queue, which doesn't always exist (in the case where it has been emptied because all items in the queue were older than the threshold). I can get around it with some try/except stuff or more conditionals, but none of that seems very pythonic.

while True:
    targettime = datetime.now() - timedelta(seconds=5 * 60)
    while queue[-1] >= targettime and len(queue) > 0:
        queue.pop()
    if len(queue) == 0:
        do_work()
    time.sleep(60)

Any advice on how to handle this better? I'm open to entirely new solutions as well, using a deque seemed like the best approach but now I'm not so sure.

🌐
Mimo
mimo.org › glossary › python › pop()
Python Pop Method: Essential Data Manipulation techniques
Python · Open in Mimo · Open in Mimo · Copy Code · tasks = ["write", "debug", "test"] while tasks: current_task = tasks.pop(0) # Remove and return the first task print(f"Executing {current_task}") You can use the pop() method to remove a specific item from a list and use it right away.
Find elsewhere
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python queue
Python Queue
October 14, 2024 - Lists are a little slow as compared with queues and the reason behind this is when we insert a new element to the list, it requires the shifting of elements by one. And this process takes O(n) time. To better understand this concept, go through the example below: ... que = [] que.append(‘Person1’) que.append(‘Person2’) que.append(‘Person3’) print(que) #List is quite slow because of the shifting of elements by one place. print(que.pop(0))
🌐
CodingNomads
codingnomads.com › python-301-use-a-list-in-stack-or-queue
Use a List in a Stack or Queue
In this example, you're using two ... the end of the collection. .pop(0), used with an argument of 0, allows you to remove the first element from the collection....
🌐
Readthedocs
pynote.readthedocs.io › en › latest › DataTypes › Stack_Queue.html
Stacks and Queues in Python — pynotes documentation
fruits = [] fruits.append('banana') fruits.append('grapes') fruits.append('mango') fruits.append('orange') first_item = fruits.pop(0) print(first_item) first_item = fruits.pop(0) print(first_item) print(fruits) ... Again, here we use the append and pop operations of the list to simulate the core operations of a queue. Subscribe to our Newsletter · Get occassional tutorials, guides, and jobs in your inbox. No spam ever. Unsubscribe at any time. Python has a deque (pronounced ‘deck’) library that provides a sequence with efficient methods to work as a stack or a queue.
🌐
Medium
basillica.medium.com › working-with-queues-in-python-a-complete-guide-aa112d310542
Working with Queues in Python — A Complete Guide | by Basillica | Medium
March 27, 2024 - In addition to the built-in data structures, you can also implement a custom queue class in Python. Here is one way to implement a basic queue: class Queue: def **init**(self): self.items = [] def size(self): return len(self.items) def enqueue(self, item): self.items.append(item) def dequeue(self): if self.size() == 0: return None return self.items.pop(0) To use it: q = Queue() q.enqueue(1) q.enqueue(2) q.enqueue(3) print(q.size()) # 3 print(q.dequeue()) # 1 print(q.dequeue()) # 2 ·
🌐
Replit
replit.com › home › discover › how to use pop() in python
How to use pop() in Python | Replit
February 13, 2026 - By repeatedly calling pop(0), you can process items from the front of a list, mimicking a First-In, First-Out (FIFO) queue.
Top answer
1 of 4
32

The first test isn't surprising; three elements are removed off the end.

The second test is a bit surprising. Only two elements are removed. Why?

List iteration in Python essentially consists of an incrementing index into the list. When you delete an element you shift all the elements on the right over. This may cause the index to point to a different element.

Illustratively:

start of loop
[0,0,0,1,2,3,4,5,6]
 ^   <-- position of index

delete first element (since current element = 0)
[0,0,1,2,3,4,5,6]
 ^

next iteration
[0,0,1,2,3,4,5,6]
   ^

delete first element (since current element = 0)
[0,1,2,3,4,5,6]
   ^

and from now on no zeros are encountered, so no more elements are deleted.


To avoid confusion in the future, try not to modify lists while you're iterating over them. While Python won't complain (unlike dictionaries, which cannot be modified during iteration), it will result in weird and usually counterintuitive situations like this one.

2 of 4
12

since in list or Stack works in last in first out[LIFO] so pop() is used it removes last element in your list

where as pop(0) means it removes the element in the index that is first element of the list

as per the Docs

list.pop([i]):

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 square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Python Library Reference.)

🌐
Python
docs.python.org › 3 › library › queue.html
queue — A synchronized queue class
February 23, 2026 - Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Empty ...
🌐
Google Groups
groups.google.com › g › comp.lang.python › c › kiHYf5N0iz8
list.pop(0) vs. collections.dequeue
On Jan 22, 1:29 pm, Christian Heimes <li...@cheimes.de> wrote: > Steve Howell wrote: > > I disagree that Python code rarely pops elements off the top of a > > list. There are perfectly valid use cases for wanting a list over a > > dequeue without having to pay O(N) for pop(0).
🌐
GeeksforGeeks
geeksforgeeks.org › python › stack-and-queues-in-python
Stack and Queues in Python - GeeksforGeeks
May 9, 2022 - Below is list implementation of queue. We use pop(0) to remove the first item from a list. ... # Python code to demonstrate Implementing # Queue using list queue = ["Amar", "Akbar", "Anthony"] queue.append("Ram") queue.append("Iqbal") print(queue) ...
🌐
Intellipaat
intellipaat.com › home › blog › queue in python – implementation explained
Queue in Python: How to Implement Queue in Python
October 14, 2025 - In this script, the enqueue() function adds an element to the queue by appending it to the end of the queue list. The dequeue() function removes the first element from the queue using the pop(0) method.