convert set to list Python

Previous
Next

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.

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]

As you can see, list starts with open square bracket and ends with close square bracket.

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog