Given a set, write a Python program to convert the given set into list.
Examples:
Input : {1, 2, 3, 4} Output : [1, 2, 3, 4] Input : {'Geeks', 'for', 'geeks'} Output : ['Geeks', 'for', 'geeks']
Approach #1 : Using list[set_name].
Typecasting to list can be done by simply using list[set_name].
['Geeks', 'for', 'geeks']
Approach #2 : using sorted[] method
Using sorted[] function will convert the set into list in a defined order. The only drawback of this method is that the elements of the set need to be sortable.
Approach #3 : Using [*set, ]
This essentially unpacks the set s inside a list literal which is created due to the presence of the single comma [, ]. This approach is a bit faster but suffers from readability.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning Basic Level Course