If you have a list of hashable objects (filenames would probably be strings, so they should count):

lst = ['foo.py', 'bar.py', 'baz.py', 'qux.py', Ellipsis]

you can construct the set directly:

s = set(lst)

In fact, set will work this way with any iterable object! (Isn't duck typing great?)


If you want to do it iteratively:

s = set()
for item in iterable:
    s.add(item)

But there's rarely a need to do it this way. I only mention it because the set.add method is quite useful.

Answer from mgilson on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ converting list to a set
r/learnpython on Reddit: Converting List to a Set
June 22, 2020 -

Greetings all,

I'm learning the very basics of Python and I'm trying to convert a list to a set in order to remove duplicate words in the list. That's possible, right?

What I have so far is as follows:

def remove_dups(self):

""" Return a new list in which all duplicates from the words, have been removed. """

words = ["show", "show"]

uniquewords = set(words)

print(remove_dups)

This is part of a larger code, but this last part is my problem area. The list of words is longer, but I deleted them to save space in this thread. Is my formatting wrong? I'm not able to get anything to print.

I'd greatly appreciate the help!

Discussions

How to convert a set to a list in python? - Stack Overflow
Works for me on Python 2.6.6 on Linux... but that first line doesn't create a set. ... You've shadowed the set builtin. Perhaps you accidently typed set=set(first_list) or something. Now set is redefined to this set object which would cause that error. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Converting a set to list
Despite your "efforts" (lizst, lst), you still have a list variable in scope somewhere, shadowing the function. If you're still in that iPython session, del list will remove it and give you the builtin back. More on reddit.com
๐ŸŒ r/learnpython
8
4
July 17, 2017
Creating a list from a set
Hi Viewer, I am a newbie to Python and I am learning lists in Python. I see list() accepts an iterable to create a list. But came across the following interesting line of code, s = {1, 2, 3} l = list(s) print(l) [1, 2, 3] If my understanding is correct a set is not an iterable type. More on discuss.python.org
๐ŸŒ discuss.python.org
10
0
November 25, 2022
convert set to a list type in python
because you're reassigning links every time inside the for loop. You need to define an empty list beforehand and then append to it. More on reddit.com
๐ŸŒ r/learnpython
5
1
February 5, 2021
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-set-into-a-list
Convert set into a list in Python - GeeksforGeeks
While it is often used for more complex transformations, it can also be used to convert a set into a list. ... Explanation: This method iterates over each item in the set and constructs a list out of it. Pythonโ€™s unpacking operator * can also be used to unpack the elements of a set into a list.
Published: July 11, 2025
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ convert list to set python
Convert List to Set Python - Scaler Topics
January 16, 2024 - The set() function will help us to convert a list to a set. The order of the set would be different, as a set displays the items in random order. Syntax: ... As you can see, the set only contains unique elements from the list. Note: A list can contain any data type; it can be a list of strings, ...
Find elsewhere
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ add-list-to-set-in-python
Adding a List to a Set in Python: 5 Things You Must Know | LearnPython.com
September 12, 2022 - Here is a table summarizing some of the common characteristics of data structures in Python: Set items are unordered, which means the items do not have a fixed position in the set and their order can change each time you use it. List items are ordered: the position of each item is always the same. Set items are immutable, which means you cannot modify item values once the set is created. However, you can remove existing items or add new items to the set.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_sets.asp
Python Sets
It is also possible to use the set() constructor to make a set. ... thisset = set(("apple", "banana", "cherry")) # note the double round-brackets print(thisset) Try it Yourself ยป ยท There are four collection data types in the Python programming language: List is a collection which is ordered and changeable.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ set-to-list-python
5 Ways to Convert Set to List in Python | FavTutor
September 26, 2021 - Python supports many in-built functions ... convert the python set into the list data type. You have to pass the python set inside the list() function as an argument, and the output will be the list of the same elements...
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ set
Mimo: The coding platform you need to learn Web Development, Python, and more.
You can convert a Python set into a list using the list() function. Similarly, you can convert a list into a set with the Python set() function. When a list contains duplicate elements, converting it to a set removes the duplicates.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ list-to-set-python
Convert List to Set in Python | 4 Methods (With Example)
September 15, 2023 - Here's an example of a list: ... A set is an unordered collection of unique elements enclosed in curly braces ({}). It does not allow duplicate elements and does not preserve the order of insertion. Sets are useful when you need to perform membership checks or remove duplicates from a collection. Here's an example of a set: ... In Python, we have four different ways to transform a list into a set.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists.asp
Python Lists
It is also possible to use the list() constructor when creating a new list. ... thislist = list(("apple", "banana", "cherry")) # note the double round-brackets print(thislist) Try it Yourself ยป ยท There are four collection data types in the Python programming language: List is a collection which is ordered and changeable. Allows duplicate members. Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Set is a collection which is unordered, unchangeable*, and unindexed.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-set-vs-list
Python Set VS List โ€“ Sets and Lists in Python
January 5, 2023 - If you're wondering which to use, it depends on the use case. If you donโ€™t want the values in the data to change, you can use a set. But if you want the items to change, you can use a list. You can also take into account whether the order of the items matters to you or not.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ converting a set to list
r/learnpython on Reddit: Converting a set to list
July 17, 2017 -

One problem I am trying to solve is to extract the unique items from an array into another array. I thought that I would convert the array into a set and cast it back into an array.

It works if i let a for loop run and append the items into a new list as follows:

lizst = [1,1,1,2,3,3,3,3,4,4]
def uniq(lst):
    to_set = set(lst)
    to_list = []
    for item in to_set:
        to_list.append(item)
    return to_list

however, then i tried to be more intelligent and tried this:

def uniq2(lst):
    return list(set(lst))

however, when I call this function as follows:

uniq2(lizst)

i get:

 <ipython-input-23-2cb8fd02733f> in uniq2(lst)
  1 def uniq2(lst):
----> 2     return list(set(lst))

TypeError: 'list' object is not callable

why am i getting this error? is there no list() function? how am i supposed to cast the set to a list then?

๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ convert set into a list in python
Convert Set into a List in Python - Scaler Topics
August 9, 2023 - One can define typecasting as converting the data or variable from one data structure to another for performing necessary operations per the need. Regarding Python set and list, multiple methods can be used to perform explicit type conversion, that is, in this case, to convert set to list.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Creating a list from a set - Python Help - Discussions on Python.org
November 25, 2022 - Hi Viewer, I am a newbie to Python and I am learning lists in Python. I see list() accepts an iterable to create a list. But came across the following interesting line of code, s = {1, 2, 3} l = list(s) print(l) [1, 2, 3] If my understanding is correct a set is not an iterable type.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-convert-a-python-list-to-a-set-while-preserving-the-original-order-417300
How to convert a Python list to a set while preserving the original order | LabEx
This technique is particularly useful when you need to remove duplicates from a list but maintain the order of the first occurrence of each unique element. By the end of this tutorial, you will understand the differences between lists and sets in Python and learn multiple techniques to convert a list to a set while maintaining the original order of elements.