Skip to content
Related Articles
Open in App
Not now

Related Articles

Python | Convert a list into tuple of lists

Improve Article
Save Article
  • Last Updated : 19 Sep, 2022
Improve Article
Save Article

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 

Python3




# 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)

Output:

(['Geeks'], ['for'], ['geeks'])

Method #2 : Using Map + Lambda 

Python3




# 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)

Output:

(['first'], ['second'], ['third'])

Method #3 : Using Map + zip 

Python3




# 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)

Output:

(['first'], ['second'], ['third'])

Method #4: Using enumerate function 

Python3




lst = ['Geeks', 'for', 'geeks']
x = tuple([i] for a,i in enumerate(lst))
print(x)

Output

(['Geeks'], ['for'], ['geeks'])

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!