The common approach to get a unique collection of items is to use a set. Sets are unordered collections of distinct objects. To create a set from any iterable, you can simply pass it to the built-in set() function. If you later need a real list again, you can similarly pass the set to the list() function.

The following example should cover whatever you are trying to do:

>>> t = [1, 2, 3, 1, 2, 3, 5, 6, 7, 8]
>>> list(set(t))
[1, 2, 3, 5, 6, 7, 8]
>>> s = [1, 2, 3]
>>> list(set(t) - set(s))
[8, 5, 6, 7]

As you can see from the example result, the original order is not maintained. As mentioned above, sets themselves are unordered collections, so the order is lost. When converting a set back to a list, an arbitrary order is created.

Maintaining order

If order is important to you, then you will have to use a different mechanism. A very common solution for this is to rely on OrderedDict to keep the order of keys during insertion:

>>> from collections import OrderedDict
>>> list(OrderedDict.fromkeys(t))
[1, 2, 3, 5, 6, 7, 8]

Starting with Python 3.7, the built-in dictionary is guaranteed to maintain the insertion order as well, so you can also use that directly if you are on Python 3.7 or later (or CPython 3.6):

>>> list(dict.fromkeys(t))
[1, 2, 3, 5, 6, 7, 8]

Note that this may have some overhead of creating a dictionary first, and then creating a list from it. If you don’t actually need to preserve the order, you’re often better off using a set, especially because it gives you a lot more operations to work with. Check out this question for more details and alternative ways to preserve the order when removing duplicates.


Finally note that both the set as well as the OrderedDict/dict solutions require your items to be hashable. This usually means that they have to be immutable. If you have to deal with items that are not hashable (e.g. list objects), then you will have to use a slow approach in which you will basically have to compare every item with every other item in a nested loop.

Answer from poke on Stack Overflow
🌐
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
Top answer
1 of 16
2340

The common approach to get a unique collection of items is to use a set. Sets are unordered collections of distinct objects. To create a set from any iterable, you can simply pass it to the built-in set() function. If you later need a real list again, you can similarly pass the set to the list() function.

The following example should cover whatever you are trying to do:

>>> t = [1, 2, 3, 1, 2, 3, 5, 6, 7, 8]
>>> list(set(t))
[1, 2, 3, 5, 6, 7, 8]
>>> s = [1, 2, 3]
>>> list(set(t) - set(s))
[8, 5, 6, 7]

As you can see from the example result, the original order is not maintained. As mentioned above, sets themselves are unordered collections, so the order is lost. When converting a set back to a list, an arbitrary order is created.

Maintaining order

If order is important to you, then you will have to use a different mechanism. A very common solution for this is to rely on OrderedDict to keep the order of keys during insertion:

>>> from collections import OrderedDict
>>> list(OrderedDict.fromkeys(t))
[1, 2, 3, 5, 6, 7, 8]

Starting with Python 3.7, the built-in dictionary is guaranteed to maintain the insertion order as well, so you can also use that directly if you are on Python 3.7 or later (or CPython 3.6):

>>> list(dict.fromkeys(t))
[1, 2, 3, 5, 6, 7, 8]

Note that this may have some overhead of creating a dictionary first, and then creating a list from it. If you don’t actually need to preserve the order, you’re often better off using a set, especially because it gives you a lot more operations to work with. Check out this question for more details and alternative ways to preserve the order when removing duplicates.


Finally note that both the set as well as the OrderedDict/dict solutions require your items to be hashable. This usually means that they have to be immutable. If you have to deal with items that are not hashable (e.g. list objects), then you will have to use a slow approach in which you will basically have to compare every item with every other item in a nested loop.

2 of 16
492

In Python 2.7, the new way of removing duplicates from an iterable while keeping it in the original order is:

>>> from collections import OrderedDict
>>> list(OrderedDict.fromkeys('abracadabra'))
['a', 'b', 'r', 'c', 'd']

In Python 3.5, the OrderedDict has a C implementation. My timings show that this is now both the fastest and shortest of the various approaches for Python 3.5.

In Python 3.6, the regular dict became both ordered and compact. (This feature is holds for CPython and PyPy but may not present in other implementations). That gives us a new fastest way of deduping while retaining order:

>>> list(dict.fromkeys('abracadabra'))
['a', 'b', 'r', 'c', 'd']

In Python 3.7, the regular dict is guaranteed to both ordered across all implementations. So, the shortest and fastest solution is:

>>> list(dict.fromkeys('abracadabra'))
['a', 'b', 'r', 'c', 'd']
Discussions

python - Deleting multiple elements from a list - Stack Overflow
Is it possible to delete multiple elements from a list at the same time? If I want to delete elements at index 0 and 2, and try something like del somelist[0], followed by del somelist[2], the second More on stackoverflow.com
🌐 stackoverflow.com
python - How to remove multiple items from a list in just one statement? - Stack Overflow
I just want to point out that the ... as many element as in the remove-list. The above method will ended up eliminating all duplicates. Not necessary the right behavior. 2021-01-03T01:07:57.333Z+00:00 ... @aluriak benchmarks as of python 3.9.7 seem to give different results. if you have a complex iterable you're filtering by, then pre-building the iterable is best, but set vs. list gives about the same ... 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 can I remove all the same objects from a list?
Hi everyone! I’ve learned Python for weeks. And this is my question. How can I remove all the same objects from a list? How to remove all the ‘5’? list1=[1,2,5,4,3,5,5,6,7,8,5,5,5,9] for i in list1: if i==5: … More on discuss.python.org
🌐 discuss.python.org
14
0
February 1, 2023
🌐
TutorialsPoint
tutorialspoint.com › how-can-i-remove-the-same-element-in-the-list-by-python
How can I remove the same element in the list by Python
May 9, 2025 - The fromkeys() method in Python accepts an iterable holding the keys and values (optional) as parameters and creates a dictionary from the provided values. In this example, we will use the fromkeys() method to create a new dictionary of unique elements and convert it to a list again - a = [1, ...
🌐
FavTutor
favtutor.com › blogs › remove-duplicates-from-list-python
How to Remove Duplicates from List in Python? (with code)
November 13, 2023 - The simplest way to remove duplicates from a list in Python is by converting the list into a set. It will automatically remove similar entries because set has a property that it cannot have duplicate values.
🌐
Delft Stack
delftstack.com › home › howto › python › remove multiple elements from list python
How to Remove Multiple Elements From a List in Python | Delft Stack
February 2, 2024 - To remove multiple values from a Python list, we can either remove the actual values of the list or the indexes of values to be removed from the list. We can use if...else control statements, list comprehension, list slicing, and for loops to ...
Find elsewhere
🌐
IncludeHelp
includehelp.com › python › program-to-remove-multiple-elements-from-a-list-using-list-comprehension.aspx
Remove multiple elements from a list in Python
June 28, 2023 - Original list: [10, 20, 30, 35, 45, 55, 10, 30, 45] List after removing elements: [10, 20, 35, 55, 10] To remove multiple elements (all occurrences of a given element) from a Python list, you can use Python list comprehension by specifying the condition. This will filter list elements excluding ...
🌐
W3Schools
w3schools.com › python › python_howto_remove_duplicates.asp
How to remove duplicates from a Python List
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers
🌐
Delft Stack
delftstack.com › home › howto › python › python list remove all
How to Remove All the Occurrences of an Element From a List in Python | Delft Stack
February 2, 2024 - In this example, we demonstrated how to use the filter() function with a lambda function to remove all instances of an element from a list. The resulting list contains only the elements that satisfy the condition specified in the lambda function, ...
🌐
Python Guides
pythonguides.com › remove-multiple-elements-from-a-list-in-python
How To Remove Multiple Items From List In Python?
April 3, 2025 - Learn how to remove multiple items from a list in Python using list comprehensions, `filter()`, or `remove()` in a loop. Efficiently clean your list with ease!
🌐
Python.org
discuss.python.org › python help
How can I remove all the same objects from a list? - Python Help - Discussions on Python.org
February 1, 2023 - Hi everyone! I’ve learned Python for weeks. And this is my question. How can I remove all the same objects from a list? How to remove all the ‘5’? list1=[1,2,5,4,3,5,5,6,7,8,5,5,5,9] for i in list1: if i==5: list1.remove(5) print(list1) the result is : [1, 2, 4, 3, 6, 7, 8, 5, 5, 9] but there are still two “5”
🌐
AskPython
askpython.com › home › remove duplicate elements from list in python
Remove Duplicate Elements from List in Python - AskPython
August 6, 2022 - To remove duplicate elements from List in Python, we can manually iterate through the list and add an element to the new list if it is not present. Otherwise, we skip that element.
🌐
Flexiple
flexiple.com › python › remove-multiple-items-list
How to Remove Multiple Items from a Python List - Flexiple
April 1, 2024 - In Python, you can use list comprehension to create a new list containing only the items that meet certain conditions. fruits = ['apple', 'banana', 'orange', 'grape', 'kiwi'] ripe_fruits = [fruit for fruit in fruits if fruit != 'banana'] Think of the filter() function as a smart filter for your list.
🌐
Studytonight
studytonight.com › python-programs › remove-multiple-elements-from-a-list-in-python
Remove multiple elements from a list in Python - Studytonight
In this approach, we will iterate over the list and remove them one by one if it is divisible by 5. We will use the remove() function to remove the particular number. Follow the algorithm to understand the approach better.
🌐
TutorialsPoint
tutorialspoint.com › article › how-do-you-remove-multiple-items-from-a-list-in-python
How do you remove multiple items from a list in Python?
September 16, 2022 - The remove() method can delete items based on conditions. We iterate over a copy to avoid index shifting issues ? # Creating a List numbers = [2, 7, 10, 14, 20, 25, 33, 38, 43] # Displaying the List print("List =", numbers) # Delete multiple ...
🌐
The Python Coding Stack
thepythoncodingstack.com › the python coding stack › i want to remove duplicates from a python list • how do i do it?
I Want to Remove Duplicates from a Python List • How Do I Do It?
July 15, 2025 - Sometimes, you don't care about the order of the elements in a list. If that's the case, you can cast the list into a set and then back into a list to remove duplicates. But sometimes, the order matters. It certainly matters when dealing with a queue of customers. Let's look at another option. Do you want to try video courses designed and delivered in the same style as these posts? You can get a free trial at The Python Coding Place and you also get access to a members-only forum.
🌐
Medium
medium.com › @rafsan.nybsys › delete-multiple-same-elements-from-python-list-c9aadb697400
Delete multiple same elements from Python List | by Rafsan Jany | Medium
September 4, 2018 - Let we have a list contains different elements. Among these elements, some elements repeat several times, for instance we have three 1s and two 3s in our list like l1 = [1, 2, 3, 4, 1, 1, 5, 6, 3, 7] We will delete the elements that occurs multiple times.
🌐
GeeksforGeeks
geeksforgeeks.org › remove-common-elements-from-two-list-in-python
Remove common elements from two list in Python - GeeksforGeeks
December 17, 2024 - A simple for loop can also be used to remove multiple elements from a list.Pythona = [10, 20, 30, 40, 50, 60, 70] # Elements to remove remove = [20, 40,