Python - Convert List of lists to list of Sets Last Updated : 12 Apr, 2025 Comments Improve Suggest changes Like Article Like Report We are given a list containing lists, and our task is to convert each sublist into a set. This helps remove duplicate elements within each sublist. For example, if we have:a = [[1, 2, 1], [1, 2, 3], [2, 2, 2, 2], [0]]The output should be:[{1, 2}, {1, 2, 3}, {2}, {0}]Let's explore some method's to achieve this.Using List ComprehensionThis method uses a one-liner loop that converts each sublist into a set using the set() constructor inside a list comprehension. Python a = [[1, 2, 1], [1, 2, 3], [2, 2, 2, 2], [0]] # list comprehension b = [set(x) for x in a] print(b) Output[{1, 2}, {1, 2, 3}, {2}, {0}] Explanation:We loop through each sublist x in a using list comprehension.Each x is converted into a set using set(x) to remove duplicates.Using map() and setWe use the map() function to apply set() to every sublist in the input list and then convert the result to a list. Python a = [[1, 2, 1], [1, 2, 3], [2, 2, 2, 2], [0]] b = list(map(set, a)) print(b) Output[{1, 2}, {1, 2, 3}, {2}, {0}] Explanation:map(set, a) applies the set function to each element of a.The result is a map object which is then converted into a list using list().Using a for Loop and set()We use a traditional for loop to iterate over each sublist and append the converted set to a new list. Python a = [[1, 2, 1], [1, 2, 3], [2, 2, 2, 2], [0]] b = [] for x in a: b.append(set(x)) print(b) Output[{1, 2, 3}, {4, 5, 6}, {8, 9, 7}]Explanation:We initialize an empty list b.For each sublist x, we convert it into a set and append it to b. Comment More infoAdvertise with us Next Article Python - Convert List of lists to list of Sets T thotasravya28 Follow Improve Article Tags : Technical Scripter Python Competitive Programming Python Programs DSA Technical Scripter 2020 Python list-programs Python set-programs +4 More Practice Tags : python Similar Reads Python | Convert List of lists to list of Strings Interconversion of data is very popular nowadays and has many applications. In this scenario, we can have a problem in which we need to convert a list of lists, i.e matrix into list of strings. Let's discuss certain ways in which this task can be performed. Method #1 : Using list comprehension + joi 4 min read Python Convert Dict of Lists to Dict of Sets In Python, converting a dictionary of lists to a dictionary of sets is a valuable process for optimizing data structures. This transformation enhances efficiency by eliminating duplicates and enabling efficient membership testing. Utilizing built-in functions like set() and list comprehension simpli 3 min read Python | Convert list of tuples to list of list Converting list of tuples to list of lists in Python is a task where each tuple is transformed into list while preserving its elements. This operation is commonly used when we need to modify or work with the data in list format instead of tuples.Using numpyNumPy makes it easy to convert a list of tu 3 min read Convert Set of Tuples to a List of Lists in Python Sets and lists are two basic data structures in programming that have distinct uses. It is sometimes necessary to transform a collection of tuples into a list of lists. Each tuple is converted into a list throughout this procedure, and these lists are subsequently compiled into a single, bigger list 3 min read Python | Convert List of String List to String List Sometimes while working in Python, we can have problems of the interconversion of data. This article talks about the conversion of list of List Strings to joined string list. Let's discuss certain ways in which this task can be performed. Method #1 : Using map() + generator expression + join() + isd 6 min read Python - Convert List of Integers to a List of Strings We are given a list of integers and our task is to convert each integer into its string representation. For example, if we have a list like [1, 2, 3] then the output should be ['1', '2', '3']. In Python, there are multiple ways to do this efficiently, some of them are: using functions like map(), re 3 min read Convert list of strings to list of tuples in Python Sometimes we deal with different types of data types and we require to inter-convert from one data type to another hence interconversion is always a useful tool to have knowledge. This article deals with the converse case. Let's discuss certain ways in which this can be done in Python. Method 1: Con 5 min read Python - Convert List of Dictionaries to List of Lists We are given list of dictionaries we need to convert it to list of lists. For example we are given a list of dictionaries a = [{'name': 'Geeks', 'age': 25}, {'name': 'Geeks', 'age': 30}] we need to convert it in list of list so that the output becomes[['Geeks',25],['Geeks;'30]].Using List Comprehens 3 min read Python | Convert list of tuples into list In Python we often need to convert a list of tuples into a flat list, especially when we work with datasets or nested structures. In this article, we will explore various methods to Convert a list of tuples into a list. Using itertools.chain() itertools.chain() is the most efficient way to flatten a 3 min read Convert List of Tuples to List of Strings - Python The task is to convert a list of tuples where each tuple contains individual characters, into a list of strings by concatenating the characters in each tuple. This involves taking each tuple, joining its elements into a single string, and creating a new list containing these strings.For example, giv 3 min read Like