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
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; } ..
Discussions

Why pop method removes two list at once?
Pop modifies the list. Here you remove an item from the list, and throw it away: guest.pop() Then you remove another item, and print it: print(f"{guest.pop()}") In your second example, you only call pop once, hence why only one item is removed. More on reddit.com
🌐 r/learnpython
27
16
December 17, 2023
python - Pop multiple elements from a set - Stack Overflow
Is there a way in python to pop multiple elements from a set, without a for loop over the pop method and without converting the set to a list? More on stackoverflow.com
🌐 stackoverflow.com
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
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
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
🌐
DataCamp
datacamp.com › tutorial › python-pop
How to Use the Python pop() Method | DataCamp
July 31, 2024 - The Python Cheat Sheet for Beginners will also help you reference and understand Python's syntax and different functions. The pop() method is used in lists and dictionaries to remove specific items and return the value. I will show a quick example for both. The first example shows how to remove ...
🌐
EyeHunts
tutorial.eyehunts.com › home › pop multiple elements python
Pop multiple elements Python
July 24, 2023 - When using pop(), it’s essential to handle the indices carefully to avoid index errors. Sorting the indices in descending order ensures that you remove elements from the end of the list first, which won’t affect the subsequent indices to remove. Alternatively, list comprehension provides a more concise and efficient way to achieve the same result without modifying the original list. ... All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
🌐
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.
Find elsewhere
🌐
W3Schools
w3schools.com › python › ref_list_pop.asp
Python List pop() Method
Python Examples Python Compiler ... Plan Python Interview Q&A Python Bootcamp Python Training ... The pop() method removes the element at the specified position....
🌐
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 is used to remove a returns last object from the list. You can also remove the element at the specified position using the pop() function by passing the index value. Note: If the index is not given, then the last element is popped out and removed from the list.
🌐
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 ... programming language. Definition and Usage: The list.pop() method removes and returns the last element from an existing list....
🌐
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']

🌐
Stack Overflow
stackoverflow.com › questions › 65051560 › pop-multiple-elements-from-a-set
python - Pop multiple elements from a set - Stack Overflow
Just to be clear: You are looking for an operation akin to removed = some_set.pop(n), which removes n elements from some_set and stores them in removed? ... Just use [myset.pop() for _ in range(n)], then. If running that loop in Python instead of a builtin is the bottleneck of your application, you have other things to worry about.
🌐
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
The syntax of using the pop() method in the Python lists is simple and straightforward. Here’s a basic example: ... The argument for the parameter index is optional. Without an argument, the default index is -1, pointing to the last element in the list. ## **When to Use pop() in Python Lists** ### Stack Data Structure A stack is a classic use case for `pop()` because it removes the last added element first (last in, first out).
🌐
DigitalOcean
digitalocean.com › community › tutorials › pop-python
How to Use `.pop()` in Python Lists and Dictionaries | DigitalOcean
July 24, 2025 - Python’s .pop() method is a powerful and flexible built-in function that allows you to remove and return elements from both lists and dictionaries. This method is especially useful in scenarios where you need to both extract and delete items in a single, efficient operation.
🌐
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?
🌐
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]
🌐
GeeksforGeeks
geeksforgeeks.org › remove-multiple-elements-from-a-list-in-python
Remove Multiple Elements from List in Python - GeeksforGeeks
Lists in Python have various built-in ... remove, pop, del and clear methods. Removing elements from a list can be done in various ways depending on whether we want to remove based on the value of the element or index.The simplest way to remove an element from a list by i · 3 min read Python | Remove given element from the list · Given a list, write a Python program to remove the given element (list may have duplicates) from the given list. There are multiple ways we can ...
Published   December 26, 2024
🌐
Iditect
iditect.com › faq › python › pop-multiple-items-from-the-beginning-and-end-of-a-list-in-python.html
Pop multiple items from the beginning and end of a list in python
To pop multiple items from the beginning and end of a list in Python, you can use slicing along with the pop() method.
🌐
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
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; } ..