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
๐ŸŒ
Narkive
python-ideas.python.narkive.com โ€บ sayXvTei โ€บ pop-multiple-elements-of-a-list-at-once
pop multiple elements of a list at once
Post by Diego Jacobi 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. The item popped is not copied.
๐ŸŒ
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
๐ŸŒ
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 ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Pop Multiple Items from a List in Python - YouTube
Learn how to efficiently `pop multiple items` from a list in Python without encountering index errors.---This video is based on the question https://stackove...
Published: March 26, 2025
Views: 6
๐ŸŒ
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']

Find elsewhere
๐ŸŒ
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 - The list.pop() method removes and returns the last element from an existing list. The list.pop(index) method with the optional argument index removes and returns the element at the position index. indices = [0, 2, 5] # must be ordered! shift = 0 for i in indices: todo_list.pop(i-shift) shift ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python list pop()
Python List pop() โ€“ Be on the Right Side of Change
June 19, 2021 - This tutorial shows you everything ... type in the Python programming language. ... The list.pop() method removes and returns the last element from an existing list....
๐ŸŒ
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....
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ pop()
Python Pop Method: Essential Data Manipulation techniques
In Python, pop() is a list method that removes and returns an element of a list. With an argument, pop() removes and returns the item at the specified index (starting from 0).
๐ŸŒ
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 - languages = ['Python', 'Java', 'C++', 'Kotlin'] # Negative value print(languages.pop(-1)) print(languages) Answer: To remove the first element from a list, just pass the index value 0 into a pop function. list1 = [1, 4, 3, 6, 7] # Remove first value print(list1.pop(0)) print(list1) ... list1 = [1, 4, 3, 6, 7] # Remove indices = {0, 2} print([v for i, v in enumerate(list1) if i not in indices])
๐ŸŒ
DEV Community
dev.to โ€บ ahf90 โ€บ atomically-popping-multiple-items-from-a-redis-list-in-python-2afa
Atomically popping multiple items from a Redis list in Python - DEV Community
October 20, 2020 - Since nobody actually uses CLIs, let's do this in Python. This script uses redis-py's Pipeline feature. Pipelines are a subclass of the base Redis class that provide support for buffering multiple commands to the server in a single request. >>> import redis >>> my_key = 'pop_trim_test' >>> r = redis.Redis(host='localhost', port=6379) >>> r.rpush(my_key, *[x for x in range(10)]) >>> pipe = r.pipeline() >>> pipe.lrange(my_key, 0, 3) >>> pipe.ltrim(my_key, 4, -1) >>> pipe.execute() [[b'0', b'1', b'2', b'3'], True]
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ remove-multiple-elements-from-a-list-in-python
Remove Multiple Elements from List in Python - GeeksforGeeks
Removing multiple elements means eliminating all occurrences of these elements and returning a new list with the remaining numbers.
Published: October 28, 2025
๐ŸŒ
CSDN
devpress.csdn.net โ€บ python โ€บ 630452b87e66823466199cc1.html
Pop multiple items from the beginning and end of a list_python_Mangs-Python
August 23, 2022 - I want to pop two items from the left (i.e. a and b) and two items from the right (i.e. h,i). I want the most concise an clean way to do this. I could do it this way myself: ... they are around 3 times faster than the first solution for _ in range(2): mylist.pop(0); mylist.pop() ... 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
๐ŸŒ
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.
๐ŸŒ
Google Groups
groups.google.com โ€บ g โ€บ python-ideas โ€บ c โ€บ 7_lxKSCoT7s
[Python-ideas] 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.