In this tutorial, we will see how to convert set to list in python.
You can use python list() function to convert set to list.It is simplest way to convert set to list.
Let’s understand with the help of example.
1 2 3 4 5 6 7 8 9 10 11 |
setOfFruits={'Apple','Orange','Banana'} print("set of Fruits:",setOfFruits) listOfFruits=list(setOfFruits) print("listOfFruits:",listOfFruits) setOfScales={1,2,3,4,5} print("set of scales:",setOfScales) listOfScales=list(setOfScales) print("list of scales:",listOfScales) |
Output:
set of Fruits: {‘Apple’, ‘Banana’, ‘Orange’}
listOfFruits: [‘Apple’, ‘Banana’, ‘Orange’] set of scales: {1, 2, 3, 4, 5}
list of scales: [1, 2, 3, 4, 5]
listOfFruits: [‘Apple’, ‘Banana’, ‘Orange’] set of scales: {1, 2, 3, 4, 5}
list of scales: [1, 2, 3, 4, 5]
As you can see, list starts with open square bracket and ends with close square bracket.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.