From a performance point of view:

  • mylist = mylist[2:-2] and del mylist[:2];del mylist[-2:] are equivalent
  • they are around 3 times faster than the first solution for _ in range(2): mylist.pop(0); mylist.pop()

Code

iterations = 1000000
print timeit.timeit('''mylist=range(9)\nfor _ in range(2): mylist.pop(0); mylist.pop()''', number=iterations)/iterations
print timeit.timeit('''mylist=range(9)\nmylist = mylist[2:-2]''', number=iterations)/iterations
print timeit.timeit('''mylist=range(9)\ndel mylist[:2];del mylist[-2:]''', number=iterations)/iterations

output

1.07710313797e-06

3.44465017319e-07

3.49956989288e-07

Answer from mxdbld on Stack Overflow
๐ŸŒ
Python
bugs.python.org โ€บ issue9218
Issue 9218: pop multiple elements of a list at once - Python tracker
July 10, 2010 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide ยท This issue has been migrated to GitHub: https://github.com/python/cpython/issues/53464
Discussions

Why pop method removes two list at once?
Your original code is calling guest.pop twice. Once before the print and once in the print. More on reddit.com
๐ŸŒ r/learnpython
27
16
December 17, 2023
How do I pop multiple items from a queue? (python)
filter(lambda x: x < 50, xs) where xs is your collection of numbers. Documentation . More on reddit.com
๐ŸŒ r/CodingHelp
3
1
October 9, 2022
python - How to remove multiple indexes from a list at the same time? - Stack Overflow
Say I have this list here: list = [a, b, c, d, e, f, g] How would I delete say indexes 2, 3, 4, and 5 at the same time? pop doesn't accept multiple values. How else do I do this? More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 14, 2019
Remove multiple elements from a list
Filter "Mango" out with a list comprehension: a = [fruit for fruit in a if fruit != "Mango"] A longer version would be: new_a = [] for fruit in a: if fruit != "Mango": new_a.append(fruit) a = new_a Edit: Thanks u/ClutchAlpha More on reddit.com
๐ŸŒ r/learnpython
11
1
August 3, 2022
๐ŸŒ
Narkive
python-ideas.python.narkive.com โ€บ sayXvTei โ€บ pop-multiple-elements-of-a-list-at-once
pop multiple elements of a list at once
It is true that to pop off a whole slice there is a more efficient way than calling pop() repeatedly -- but there's no need for a new primitive operation, as it can already be done by copying and then deleting the slice (again, the copying only copies the pointers). Try reading up on Python's memory model for objects, it will be quite enlightening. ... Post by Guido van Rossum I think yo misunderstand the implementation of lists (and the underlying malloc()). You can't break the memory used for the list elements into two pieces and give new ownership to a (leading) section of it.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_list_pop.asp
Python List pop() Method
Remove List Duplicates Reverse ... Python Study Plan Python Interview Q&A Python Training ... The pop() method removes the element at the specified position....
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ pop multiple elements python
Pop multiple elements Python
July 24, 2023 - Note: The pop() method is used to remove and return a single element from a list based on its index. Simple example code. ... my_list = [1, 2, 3, 4, 5, 6] indices_to_remove = [1, 3] # Sort the indices in descending order to avoid index errors ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ why pop method removes two list at once?
r/learnpython on Reddit: Why pop method removes two list at once?
December 17, 2023 -

I'm doing the Python Crash Course and I got to this exercise, and I was wondering why the pop method is removing two list of my guest.

guest = ['aaron', 'john', 'pedro', 'kevin', 'mark', 'brad'] 
print(guest) 
guest.pop() 
print(f"{guest.pop()}") 
print(guest)

Output:
['aaron', 'john', 'pedro', 'kevin', 'mark', 'brad'] 
mark 
['aaron', 'john', 'pedro', 'kevin']

I tried assigning it with variable now it works. How is it different from the first though?

guest = ['aaron', 'john', 'pedro', 'kevin', 'mark', 'brad'] 
print(guest) 
guest_1 = guest.pop() 
print(f"{guest_1}") 
print(guest)

Output:
['aaron', 'john', 'pedro', 'kevin', 'mark', 'brad'] 
brad 
['aaron', 'john', 'pedro', 'kevin', 'mark']

๐ŸŒ
TechBeamers
techbeamers.com โ€บ python-list-pop
List Pop Method - TechBeamers
November 30, 2025 - The pop() method is also very efficient. It removes the specified element from the list in a single operation, without having to copy the entire list. This makes it a good choice for removing elements from large lists.
Find elsewhere
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ python pop() function | first, by value, pop multiple examples
Python pop() Function | First, by value, pop multiple Examples - EyeHunts
July 28, 2021 - Python pop() function removes a returns last object from the list.it also removes the element at the specified position using pop function by passing index.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ the most pythonic way to remove multiple items from a list
The Most Pythonic Way to Remove Multiple Items From a List - Be on the Right Side of Change
June 26, 2020 - Though, there is a pitfall to this solution. After we remove the element at index 0, all the other elements shift, and their indices change because the element at index 1 is now at index 0 and so on. ... The list.pop() method removes and returns the last element from an existing list.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-pop
How to Use the Python pop() Method | DataCamp
July 31, 2024 - When you use the pop() method without an argument or with -1 as the index to remove the last element, it operates in O(1) time because it only removes the last element in the list without changing the other elements. When we use the pop() method to remove the first or any other element, it ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-list-pop-how-to-pop-an-element-from-a-array
Python list.pop() โ€“ How to Pop an Element from a Array
February 9, 2023 - In this article, you'll learn how to remove elements in a Python list using: The pop() method.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ pop()
Python Pop Method: Essential Data Manipulation techniques
In Python, popping from a list requires shifting all other elements in the background.
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ list โ€บ list_pop.php
Python List pop() Method
April 14, 2026 - The pop() method removes the element at the specified index, regardless of whether the element appears multiple times in the list. 10. Does the Python list pop() method require the element to exist in the list?
๐ŸŒ
Python
mail.python.org โ€บ pipermail โ€บ python-ideas โ€บ 2010-July โ€บ 007575.html
[Python-ideas] pop multiple elements of a list at once
September 10, 2013 - If my scenario is yet no clear i give below some more details: When i think on how this will work on memory: def pop_slice(lis, n): tem = lis[:-n] del lis[:-n] return tem I think in "copying the elements of an array": BYTE* pop_slice(BYTE* list, unsigned int n){ BYTE* temp = malloc(n*sizeof(BYTE)); int i; for(i=0 ; i < n ; i++) { temp[i] = list[i]; } free(list, n); return temp; } Most python books and tutorials clearly says that this operation L[start:end] copies the elements requested. And being copy i understand the above behavior, which is less efficient than advancing the pointer. But i wanted to do (with "pop multiple bytes at once") is: typedef unsigned char BYTE; BYTE array[BIG_SIZE]; BYTE* incomming_buffer_pointer = &array[0]; BYTE* incomming_packet_pointer = &array[0]; BYTE* pop_slice(BYTE* list, unsigned int n){ BYTE* temp; temp = list; list = &list[n]; return temp; } ..
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python list pop()
Python List pop() โ€“ Be on the Right Side of Change
June 19, 2021 - You can call this method on each list object in Python. Hereโ€™s the syntax: ... The method list.pop() has return value Object. It removes the particular element from the list (default: the last element) and returns it directly to the caller.
๐ŸŒ
Google Groups
groups.google.com โ€บ g โ€บ python-ideas โ€บ c โ€บ 7_lxKSCoT7s
[Python-ideas] pop multiple elements of a list at once
On Sun, Jul 11, 2010 at 7:58 PM, Diego Jacobi <jacob...@gmail.com> wrote: > I guess that it would be improved if i can just pop a defined number > of elements, like this: > > pop self.recv_buffer[:-size] > or > self.recv_buffer.pop(,-size) > > That would be... "pop from (the last element minus size) to (the last element)" > in that way there is only one memory transaction. > The new list (or maybe a tuple) points to the old memory address and > the recv_buffer is advanced to a one new address.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-pop-how-to-pop-from-a-list-or-an-array-in-python
Python .pop() โ€“ How to Pop from a List or an Array in Python
March 1, 2022 - Besides just removing the item, pop() also returns it. This is helpful if you want to save and store that item in a variable for later use. #list of programming languages programming_languages = ["Python", "Java", "JavaScript"] #print initial list print(programming_languages) #remove last item, which is "JavaScript", and store it in a variable front_end_language = programming_languages.pop() #print list again print(programming_languages) #print the item that was removed print(front_end_language) #output #['Python', 'Java', 'JavaScript'] #['Python', 'Java'] #JavaScript
๐ŸŒ
Grokbase
grokbase.com โ€บ t โ€บ python โ€บ python-ideas โ€บ 107bmskjwg โ€บ pop-multiple-elements-of-a-list-at-once
[Python-ideas] pop multiple elements of a list at once - Grokbase
On 7/11/2010 1:58 PM, Diego Jacobi wrote: The thing i found is that, to pop a variable chunk of data from this buffer without copying it and deleting the elements, i have to pop one element at the time.In CPython, popping copies a reference and them deletes it from the list.