This post will discuss how to convert a set to a list in Python and vice versa.

1. Using constructor

The standard way to convert a set into a list is with the list constructor.

Download  Run Code

 
Similarly, you can use the set constructor to convert a list into a set.

Download  Run Code

2. Using Iterable Unpacking Operator

Here, the idea is to use the *-operator to unpack the items from the set inside [] syntax, which would convert a set into a list.

Download  Run Code

 
Similarly, to convert a list into a set, you can unpack the list inside the new syntax for set literal {}.

Download  Run Code

3. Using extend() function

Another solution to convert a set into a list is using the extend() function to copy elements of the set into an empty list.

Download  Run Code

 
Note that the extend() function is not available for a set. However, you can use the union() function to effectively convert a list into a set, as shown below:

Download  Run Code

That’s all about converting a Set to a list in Python.