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
1 2 3 4 5 6 7 | #creating set s = set({1, 2, 3, 4, 5, "pencil", "programmer"}) print("Set: ", x) #converting set into list l = list(s) print("List: ",l) |
Output
1 2 | Set: {1, 2, 3, 4, 5, 'pencil', 'programmer'} List: [1, 2, 3, 4, 5, 'pencil', 'programmer'] |
Any doubts then comment below.