Example:
tuple = ("python", "includehelp", 43, 54.23)
Tuple to tuples is a nested collection in which a tuple consists of tuples as elements.
List is a sequence data type. It is mutable as its values in the list can be modified. It is a collection of ordered sets of values enclosed in square brackets [].
List of Lists is a nested collection in which a list consists of lists as elements.
Converting List of Lists to Tuple of Tuples
We have a list of lists and we will be converting it to a tuple of tuples.
For this, we will be taking each tuple from the tuple to tuples and converting it into a tuple. And then convert the whole encapsulating list to a tuple. In python, we can perform this task using multiple ways.
Method 1:
One way to solve the problem is by converting each list of the list of list to tuple individually using tuple() method. And then converting the main container. This is done using list comprehension along with the tuple() method.
Output:
Method 2:
One method that can solve the problem is by using map() to map the converted individual list which will be converted using tuple() method.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer