You could just slice the list:

mainlist = [5,4,3,2,1]
n = 3
mainlist, mylist = mainlist[:n], mainlist[n:]

Keep in mind that for slicing, the first index is inclusive, while the second is exclusive, so mainlist wouldn't contain index 3 but mylist would.

Answer from ccl on Stack Overflow
Discussions

python - Pop multiple items from the beginning and end of a list - Stack Overflow
Suppose I have a list of items like this: mylist=['a','b','c','d','e','f','g','h','i'] 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 More on stackoverflow.com
🌐 stackoverflow.com
python - pop the first N elements - Stack Overflow
The naming was just an example, in your example, does the elements get removed from the list? 2018-07-07T19:28:57Z+00:00 ... Good point. I just updated my answer to update list as well. 2018-07-07T19:29:45.65Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 0 (Python) Using pop ... More on stackoverflow.com
🌐 stackoverflow.com
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
python - The most efficient way to remove the first N elements from a list - Stack Overflow
If you need to obtain elements from the beginning of the list, you should use collections.deque by Raymond Hettinger and its popleft() method. More on stackoverflow.com
🌐 stackoverflow.com
🌐
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
Master Python from basics to advanced topics, including data structures, functions, classes, and error handling ... Start your coding journey with Python. Learn basics, data types, control flow, and more ... This method modifies the original list in-place. ... fruits = ['apple', 'banana', 'cherry', 'date'] # 1. Pop the last item (no index provided) last_fruit = fruits.pop() print(f"Popped item: {last_fruit}") # Outputs: Popped item: date print(f"List is now: {fruits}") # Outputs: List is now: ['apple', 'banana', 'cherry'] # 2.
🌐
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 - The optional parameter is the index of the item you want to remove. By default, if there is no index specified, the pop() method will remove the last item that is contained in the list.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-pop-method
Python List pop() Method - GeeksforGeeks
July 17, 2026 - DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 17 Jul, 2026 · pop() method removes an element from a list and returns the removed value.
🌐
Programiz
programiz.com › python-programming › methods › list › pop
Python List pop() (with Code Visualization)
Online Python Online JavaScript Online SQL Online Java Online HTML Online C Online C++ Online C# Online PHP Online Swift Online Kotlin Online TypeScript Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The list pop() method removes and returns the item at a specified index. ...
🌐
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']

🌐
Note.nkmk.me
note.nkmk.me › home › python
Remove an Item from a List in Python: remove, pop, clear, del | note.nkmk.me
April 17, 2025 - In Python, you can remove items (elements) from a list using methods such as remove(), pop(), and clear(). You can also use the del statement to delete items by index or slice. Additionally, list comp ...
🌐
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 - The del keyword. You can use the pop() method to either remove a specific element in a list or to remove the last element. When a parameter is used, you can specify the particular element (using the element's index number...
🌐
Narkive
python-ideas.python.narkive.com › sayXvTei › pop-multiple-elements-of-a-list-at-once
pop multiple elements of a list at once
The thing is that the elements on my list are just bytes. (unsigned char), and i think that an array of this type of data is called in python immutable, which means that i may not be using the right datatype. Anyway. slice support on pop(), and/or the ability to skip elements in a for loop without restarting the iteration will clear up a lot of code.
🌐
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....
🌐
DataCamp
datacamp.com › tutorial › python-pop
How to Use the Python pop() Method | DataCamp
July 31, 2024 - I write practical, industry-focused ... and business impact, helping professionals turn data into confident decisions. The pop() method removes and returns n element from lists or dictionaries....
🌐
Medium
medium.com › teqius › python-pop-remove-items-from-lists-dictionaries-sets-and-more-a3e59daeff45
Python Pop: Remove Items From Lists, Dictionaries, Sets, and More | by John Akhilomen | teqius | Medium
November 26, 2024 - We will use the existing “my_list” that we declared earlier and apply the “pop()” function by specifying an index value. ... Now if we output the popped item, we see “milk” on the terminal.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-remove-last-n-elements-from-list
Remove first or last N elements from a List in Python | bobbyhadz
The slice my_list[:len(my_list) - n] starts at the beginning of the list and goes up to, but not including the Nth element in the list. The len() function returns the length (the number of items) of an object.
Top answer
1 of 3
18

Are your lists large? If so, use ifilter from itertools to filter out elements that you don't want lazily (with no up front cost).

Lists not so large? Just use a list comprehension:

 newlist = [x for x in oldlist if x not in ['a', 'c'] ]

This will create a new copy of the list. This is not generally an issue for efficiency unless you really care about memory consumption.

As a happy medium of syntax convenience and laziness ( = efficiency for large lists), you can construct a generator rather than a list by using ( ) instead of [ ]:

interestingelts = (x for x in oldlist if x not in ['a', 'c'])

After this, you can iterate over interestingelts, but you can't index into it:

 for y in interestingelts:    # ok
    print y

 print interestingelts[0]     # not ok: generator allows sequential access only
2 of 3
15

You want a list comprehension:

L = [c for c in L if c not in ['a', 'c']]

Or, if you really don't want to create a copy, go backwards:

for i in reversed(range(len(L))):
    if L[i] in ['a', 'c']:
        L.pop(i)    # del L[i] is more efficient

Thanks to ncoghlan for reversed() & phooji for del L[i] suggestions. (I decided to leave it as L.pop(i), since that's how the question was initially formulated.)

Also, as J.S. Sebastian correctly points out, going backwards is space efficient but time inefficient; most of the time a list comprehension or generator (L = (...) instead of L = [...]) is best.

Edit:

Ok, so since people seem to want something less ridiculously slow than the reversed method above (I can't imagine why... :) here's an order-preserving, in-place filter that should differ in speed from a list comprehension only by a constant. (This is akin to what I'd do if I wanted to filter a string in c.)

write_i = 0
for read_i in range(len(L)):
    L[write_i] = L[read_i]
    if L[read_i] not in ['a', 'c']:
         write_i += 1

del L[write_i:]
print L
# output: ['b', 'd']
🌐
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.