Write a Python program to Convert Set to List


This program demonstrates the conversion of a set into a list. The first line creates a set val with the elements 'T', 'u', 't', 'o', 'r', 'J', 'o', 'e' and 's'. The second line prints the set and its type, which is set. Next, the program converts the set val into a list and assigns it to the variable s. The line s = list(val) converts the set val into a list and stores the result in s. The last two lines print the list s and its type, which is list.

Source Code

val = {'T', 'u', 't', 'o', 'r', 'J', 'o', 'e' , 's'}
print(val)
print(type(val))
 
print("\nConvert Set Into List\n")
s = list(val)
print(s)
print(type(s))

Output

{'u', 'o', 'e', 'T', 'r', 'J', 's', 't'}
<class 'set'>

Convert Set Into List

['u', 'o', 'e', 'T', 'r', 'J', 's', 't']
<class 'list'>