- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert set into a list in Python
As part of data analysis using Python we may be required to to convert the data container from set to list. In this article we'll see e how to solve this requirement.
With list
This is a straightforward approach in which we directly apply the list function on the given set. The elements get converted into elements of a list.
Example
setA = {'Mon', 'day', '7pm'} # Given Set print("Given set : \n", setA) res = (list(setA) ) # Result print("Final list: \n",res)
Output
Running the above code gives us the following result −
Given set : ['7pm', 'Mon', 'day'] Final list: ['7pm', 'Mon', 'day']
With *
The star operator can take in the list and by applying the square brackets around it we get a list.
Example
setA = {'Mon', 'day', '7pm'} # Given Set print("Given set : \n", setA) res = [*setA, ] # Result print("Final list: \n",res)
Output
Running the above code gives us the following result −
Given set : {'Mon', '7pm', 'day'} Final list: ['Mon', '7pm', 'day']
- Related Articles
- Convert a Set into a List in Java
- Python - Convert a set into dictionary
- Convert a nested list into a flat list in Python
- Convert a string representation of list into list in Python
- Convert list into list of lists in Python
- Convert list of tuples into list in Python
- Python - Convert given list into nested list
- Convert a list into tuple of lists in Python
- Python program to convert Set into Tuple and Tuple into Set
- How to convert a list into a tuple in Python?
- Convert list of tuples into digits in Python
- Convert list of string into sorted list of integer in Python
- Convert a list of multiple integers into a single integer in Python
- Python program to convert a list of tuples into Dictionary
- Python - Convert a list of lists into tree-like dict

Advertisements