Python | Convert a list into tuple of lists
We are given a list, the task is to convert the list into tuple of lists.
Input: ['Geeks', 'For', 'geeks'] Output: (['Geeks'], ['For'], ['geeks']) Input: ['first', 'second', 'third'] Output: (['first'], ['second'], ['third'])
Method #1 : Using Comprehension
# Python code to convert a list into tuple of lists # Initialisation of list Input = ['Geeks', 'for', 'geeks'] # Using list Comprehension Output = tuple([name] for name in Input) # printing output print(Output) |
chevron_right
filter_none
Output:
(['Geeks'], ['for'], ['geeks'])
Method #2 : Using Map + Lambda
# Python code to convert a list into tuple of lists # Initialisation of list Input = ['first', 'second', 'third'] # Using map + lambda Output = tuple(map(lambda x: [x], Input)) # printing output print(Output) |
chevron_right
filter_none
Output:
(['first'], ['second'], ['third'])
Method #3 : Using Map + zip
# Python code to convert a list into tuple of lists # Initialisation of list Input = ['first', 'second', 'third'] # Using Map + zip Output = tuple(map(list, zip(Input))) # printing output print(Output) |
chevron_right
filter_none
Output:
(['first'], ['second'], ['third'])
Recommended Posts:
- Python | Ways to iterate tuple list of lists
- Python | Convert a list into a tuple
- Python | Convert list to indexed tuple list
- Python | Convert Integral list to tuple list
- Python | Convert list of tuple into dictionary
- Python | Convert list into list of lists
- Python | Convert list of tuples to dictionary value lists
- Python | Convert a list of lists into tree-like dict
- Python | Convert column to separate elements in list of lists
- Python | Sort tuple list by Nth element of tuple
- Python | Sort lists in tuple
- Python | Unpacking tuple of lists
- Python | Find number of lists in a tuple
- Python | Convert String to Tuple
- Python | Convert tuple to float value
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



