Skip to content
Related Articles

Related Articles

Python | Convert a list into tuple of lists
  • Last Updated : 13 Feb, 2019

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)
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)
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)
Output:
(['first'], ['second'], ['third'])

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :