 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Convert List of lists to List of Sets
When it is required to convert a list of list to a list of set, the ‘map’, ‘set’, and ‘list’ methods are used.
Example
Below is a demonstration of the same
my_list = [[2, 2, 2, 2], [1, 2, 1], [1, 2, 3], [1,1], [0]] print("The list of lists is: ") print(my_list) my_result = list(map(set, my_list)) print("The resultant list is: ") print(my_result)  Output
The list of lists is: [[2, 2, 2, 2], [1, 2, 1], [1, 2, 3], [1, 1], [0]] The resultant list is: [set([2]), set([1, 2]), set([1, 2, 3]), set([1]), set([0])]
Explanation
- A list of list is defined and is displayed on the console. 
- The list is converted to a set using the ‘map’ function. 
- This is again converted to a list. 
- This is assigned to a variable. 
- This is displayed as output on the console. 
Advertisements
 