Problem: We are given a set and is asked to convert it into a list in python.

To convert a set, we need to use list() method with the given set as a parameter.

Set to List in Python

#creating set
s = set({1, 2, 3, 4, 5, "pencil", "programmer"})
print("Set: ", x)

#converting set into list
l = list(s)
print("List: ",l)


Set:  {1, 2, 3, 4, 5, 'pencil', 'programmer'}
List:  [1, 2, 3, 4, 5, 'pencil', 'programmer']

Any doubts then comment below.

Leave a Reply