๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 50856c70e033eb0200006b08
1.4 Use remove not pop. (Just feed back and better hint alternative) | Codecademy
The hint says to use `.pop` but that removes the **second** index as where `.remove` actually removes the value of that index and moves every index n...
๐ŸŒ
Rustcodeweb
rustcodeweb.com โ€บ 2025 โ€บ 08 โ€บ opposite-of-append-in-python-list-pop-remove.html
What is the Opposite of append()? Using pop() and remove() in Python Lists | RUSTCODE
August 4, 2025 - In Python, the main methods are pop() and remove(). Use Cases: Data processing, stack/queue operations, dynamic list management. The pop() method removes and returns an item at a given index (default is the last item). This is considered the opposite of append() in many scenarios, especially for stacks and dynamic lists. fruits = ['apple', 'banana', 'cherry'] removed_item = fruits.pop() print("Removed:", removed_item) print("Updated list:", fruits)
Discussions

Difference between pop and remove
Also, pop returns that value that was removed, remove doesnโ€™t. More on reddit.com
๐ŸŒ r/learnpython
10
3
June 29, 2022
python - Issue with reversing list using list.pop() - Stack Overflow
0 (Python) Using pop in python to take first element print it and then put it at the bottom of the list More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to reverse order to pop out Python 3.6.4 - Stack Overflow
Instead of it deleting the 'ALL' first, I would like the popitem to delete the 'CS' first and continue in that order from top to bottom. Here is my code: my_dictionary ={ 's02.001':'CS', 's02.00... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 5, 2020
python - How do I remove the first item from a list? - Stack Overflow
How do I remove the first item from a list? [0, 1, 2, 3] โ†’ [1, 2, 3] More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ what-is-difference-between-del-remove-and-pop-on-python-lists
Difference Between Del, Remove and Pop in Python Lists - GeeksforGeeks
July 23, 2025 - remove() method deletes values or objects from the list using value and del and pop() deletes values or objects from the list using an index. del is a Python Keyword that is used to delete items from a list by index or to remove the entire list.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-reverse-a-list-in-Python-using-pop-and-append
How to reverse a list in Python using .pop() and .append() - Quora
Answer (1 of 3): So pop() by default removes an item from the list (the default is to remove the last item, but there is an index parameter to enable us to pop any item), and append() always adds an item to the end of the list. Lets imagine we have this list : 1, 2, 3, 4 and we want to end up ...
๐ŸŒ
Python
docs.python.org โ€บ 3.1 โ€บ tutorial โ€บ datastructures.html
https://docs.python.org/3.1/tutorial/datastructure...
September 4, 2012 - There is a way to remove an item from a list given its index instead of its value: the del statement. This differs from the pop() method which returns a value. The del statement can also be used to remove slices from a list or clear the entire list (which we did earlier by assignment of an ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_list_pop.asp
Python List pop() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... The pop() method removes the element at the specified position.
๐ŸŒ
Stanford
web.stanford.edu โ€บ class โ€บ archive โ€บ cs โ€บ cs106a โ€บ cs106a.1202 โ€บ handouts โ€บ py-list.html
Python Lists
Mnemonic: the exact opposite of append(). lst.pop(index) - alternate version with the index to remove is given, e.g. lst.pop(0) removes the element at index 0.
Find elsewhere
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.6 documentation
There is a way to remove an item from a list given its index instead of its value: the del statement. This differs from the pop() method which returns a value. The del statement can also be used to remove slices from a list or clear the entire ...
๐ŸŒ
The Teclado Blog
blog.teclado.com โ€บ python-lists-remove-vs-pop
Python lists: remove() vs pop() - The Teclado Blog
August 24, 2022 - Learn how and when to use the remove() and pop() methods to remove items from a Python list.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ removing items from python lists: `del` vs `pop` vs `remove`
Removing items from Python lists: `del` vs `pop` vs `remove` | Sentry
3 weeks ago - For example: mylist = ['a', 'b', 'c', 'c', 'd'] mylist.remove('c') print(mylist) # will print ['a', 'b', 'c', 'd'] mylist.remove('c') # will remove the remaining 'c' print(mylist) # will print ['a', 'b', 'd'] try: mylist.remove('c') # will raise a value error as there is no 'c' except ValueError: print('Value not found in list.') The list.pop() method called without any arguments allows us to use a Python list as a stack, removing and returning the last item in the list.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-pop-and-remove-in-a-list-in-Python
What is the difference between pop() and remove() in a list in Python? - Quora
Answer (1 of 5): [code ]pop()[/code] takes an index as its argument and will remove the element at that index. If no argument is specified, [code ]pop()[/code] will remove the last element. [code ]pop() [/code]also returns the element it removed. [code ]remove()[/code] takes an element as its ar...
Top answer
1 of 4
5

How about a simple reversal of string.

>>> x = 'abcd'
>>> x[::-1]
'dcba'
>>> 

On your code:

Never mutate the list on which you are iterating with. It can cause subtle errors.

>>> strList = [1, 2, 3, 4, 5]
>>> reverseCharList = []
>>> for someChar in strList:
...     print strList
...     reverseCharList.append(strList.pop())
...     print strList
... 
[1, 2, 3, 4, 5]   <-- Iteration 1
[1, 2, 3, 4]
[1, 2, 3, 4]      <-- Iteration 2
[1, 2, 3]
[1, 2, 3]         <-- Iteration 3
[1, 2]

See the following. Since you are using iterator (for .. in ..). You can see the iterator details directly and how mutating the list messes up with iterator.

>>> strList = [1, 2, 3, 4, 5]
>>> k = strList.__iter__()
>>> k.next()
1
>>> k.__length_hint__()   <--- Still 4 to go
4
>>> strList.pop()         <---- You pop an element
5
>>> k.__length_hint__()   <----- Now only 3 to go
3
>>> 
>>> k.next()
2
>>> k.__length_hint__()
2
2 of 4
5
for someChar in strList:
    reverseCharList.append(strList.pop())

Is essentially the same as:

i = 0
while i < len(strList):
    reverseCharList.append(strList.pop())
    i += 1

First iteration i is 0, len(strList) is 4, and you pop+append 'd'.

Second iteration i is 1, len(strList) is 3, and you pop+append 'c'.

Third iteration i is 2, len(strList) is 2, so the loop condition fails and you're done.

(This is really done with an iterator on the list, not a local variable 'i'. I've shown it this way for clarity.)

If you want to manipulate the sequence you're iterating over it's generally better to use a while loop. eg:

while strList:
    reverseCharList.append(strList.pop())
๐ŸŒ
Boot.dev
boot.dev โ€บ lessons โ€บ 3b8f1f79-c00f-4534-9aa7-87baf1c727ce
Learn to Code in Python: Pop Values | Boot.dev
.pop() is the opposite of .append(). Pop removes the last element from a list and returns it for use. For example:
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ odd behavior of list.pop() method and del funtion
r/learnpython on Reddit: Odd behavior of list.pop() method and del funtion
February 9, 2022 -

I've been strugling with a program implementation for some time now, and I just noticed a very wierd behavior of the pop method (pop is in my file, and del, as an alternative, returned the same result). Here is a minimun reproductible example:

words = (5*'Loren ipsun ').split()
print(words,'\n')
for i in range(10):
    words.pop(i)
    print(words)

This is the console output:

['Loren', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun'] 

['ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun']
['ipsun', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun']
['ipsun', 'ipsun', 'ipsun', 'Loren', 'ipsun', 'Loren', 'ipsun']
['ipsun', 'ipsun', 'ipsun', 'ipsun', 'Loren', 'ipsun']
['ipsun', 'ipsun', 'ipsun', 'ipsun', 'ipsun']
Traceback (most recent call last):

IndexError: pop index out of range

Could someone explain to me why just Loren words are being erased?

[Edit] Solution:

words = (5*'Loren ipsun ').split()
print(words,'\n')
for i in range(10):
    words.pop(0)
    print(words)
๐ŸŒ
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.