Python - Convert a list into tuple of lists Last Updated : 17 Jan, 2025 Comments Improve Suggest changes Like Article Like Report When working with data structures in Python, there are times when we need to convert a list into a tuple of smaller lists.For example, given a list [1, 2, 3, 4, 5, 6], we may want to split it into a tuple of two lists like ([1, 2, 3], [4, 5, 6]). We will explore different methods to achieve this conversion.Using slicingThis method is simple and relies on Python's list slicing capabilities. It allows us to split the original list into sublists based on specified indices. Python # Input list a = [1, 2, 3, 4, 5, 6] # Split the list into two parts using slicing res = (a[:3], a[3:]) print(res) Output([1, 2, 3], [4, 5, 6]) Explanation:We use slicing to divide the list a into two parts: one containing the first three elements and the other containing the rest.The sliced sublists are then packed into a tuple.This method is efficient and works well for scenarios where we know the split indices.Let's explore some more methods and see how we can convert a list into tuples of lists.Table of ContentUsing zip() with iteratorsUsing list comprehensionUsing a loopUsing zip() with iteratorsThis method utilizes zip() and iterators to group elements from the list into smaller lists dynamically. Python a = [1, 2, 3, 4, 5, 6] # Split the list using zip and iterators res = tuple(zip(a[:len(a)//2], a[len(a)//2:])) print(res) Output((1, 4), (2, 5), (3, 6)) Explanation:zip() function pairs elements from the first half of the list with elements from the second half.This method is useful when we want a pair-wise grouping of elements.Using list comprehensionThis method provides a compact way to achieve the desired result using list comprehension. Python a = [1, 2, 3, 4, 5, 6] # Split the list into a tuple of sublists res = tuple([a[i::2] for i in range(2)]) print(res) Output([1, 3, 5], [2, 4, 6]) Explanation:We use list comprehension to create two sublists: one containing elements at even indices and the other at odd indices.These sublists are then packed into a tuple.This method is flexible and compact but may be less intuitive than slicing.Using a loopWe can use a for loop, especially when the size of the sublists needs to be calculated dynamically. Python a = [1, 2, 3, 4, 5, 6] # Initialize an empty tuple res = () # Determine the split index split_index = len(a) // 2 # Create the sublists and add them to the tuple res += (a[:split_index], a[split_index:]) print(res) Output([1, 2, 3], [4, 5, 6]) Explanation:We calculate the split index dynamically as half the length of the list.We use slicing to create the sublists and then add them to the tuple.This method provides flexibility for handling lists where the split index is determined programmatically. Comment More infoAdvertise with us Next Article Python - Convert a list into tuple of lists everythingispossible Follow Improve Article Tags : Python Python Programs python-list Python list-programs Practice Tags : pythonpython-list Similar Reads 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 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 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 Python | Convert list into list of lists Given a list of strings, write a Python program to convert each element of the given list into a sublist. Thus, converting the whole list into a list of lists. Examples: Input : ['alice', 'bob', 'cara'] Output : [['alice'], ['bob'], ['cara']] Input : [101, 202, 303, 404, 505] Output : [[101], [202], 5 min read Python | Convert list of tuples into digits Given a list of tuples, the task is to convert it into list of all digits which exists in elements of list. Letâs discuss certain ways in which this task is performed. Method #1: Using re The most concise and readable way to convert list of tuple into list of all digits which exists in elements of l 6 min read Convert List of Lists to Dictionary - Python We are given list of lists we need to convert it to python . For example we are given a list of lists a = [["a", 1], ["b", 2], ["c", 3]] we need to convert the list in dictionary so that the output becomes {'a': 1, 'b': 2, 'c': 3}. Using Dictionary ComprehensionUsing dictionary comprehension, we ite 3 min read Convert List of Tuples To Multiple Lists in Python When working with data in Python, it's common to encounter situations where we need to convert a list of tuples into separate lists. For example, if we have a list of tuples where each tuple represents a pair of related data points, we may want to split this into individual lists for easier processi 3 min read Convert List to Tuple in Python The task of converting a list to a tuple in Python involves transforming a mutable data structure list into an immutable one tuple. Using tuple()The most straightforward and efficient method to convert a list into a tuple is by using the built-in tuple(). This method directly takes any iterable like 2 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 Convert set into a list in Python In Python, sets are unordered collections of unique elements. While they're great for membership tests and eliminating duplicates, sometimes you may need to convert a set into a list to perform operations like indexing, slicing, or sorting. For example, if input set is {1, 2, 3, 4} then Output shoul 3 min read Like