Skip to content
Related Articles

Related Articles

Python | Convert list of tuples into list

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 23 Aug, 2022
View Discussion
Improve Article
Save Article

Given a list of tuples, write a Python program to convert it into list. 

Examples:

Input: [(11, 20), (13, 40), (55, 16)]
Output:[11, 20, 13, 40, 55, 16]

Input: [('Geeks', 2), ('For', 4), ('geek', '6')]
Output: ['Geeks', 2, 'For', 4, 'geek', '6']

Below are methods to convert list of tuples into list. 

Method #1: Using list comprehension 

Python3




# Python code to convert list of tuples into list
 
# List of tuple initialization
lt = [('Geeks', 2), ('For', 4), ('geek', '6')]
 
# using list comprehension
out = [item for t in lt for item in t]
 
# printing output
print(out)

Output:

['Geeks', 2, 'For', 4, 'geek', '6']

Method #2: Using itertools 

Python3




# Python code to convert list of tuple into list
 
# Importing
import itertools
 
# List of tuple initialization
tuple = [(1, 2), (3, 4), (5, 6)]
 
# Using itertools
out = list(itertools.chain(*tuple))
 
# printing output
print(out)

Output:

[1, 2, 3, 4, 5, 6]

Method #3: Using iteration 

Python3




# Python code to convert list of tuple into list
 
# List of tuple initialization
tup = [(1, 2), (3, 4), (5, 6)]
 
# result list initialization
result = []
 
for t in tup:
    for x in t:
        result.append(x)
 
# printing output
print(result)

Output:

[1, 2, 3, 4, 5, 6]

Method #4: Using sum 

Python3




# Python code to convert list of tuple into list
 
# List of tuple initialization
tup = [(1, 2), (3, 4), (5, 6)]
 
# using sum function()
out = list(sum(tup, ()))
 
# printing output
print(out)

Output:

[1, 2, 3, 4, 5, 6]

Method #5: Using operator and reduce 

Python3




# Python code to convert list of tuple into list
 
import operator
from functools import reduce
 
# List of tuple initialization
tup = [(1, 2), (3, 4), (5, 6)]
 
# printing output
print(list(reduce(operator.concat, tup)))

Output:

[1, 2, 3, 4, 5, 6]

Method #6: Using lambda 

Python3




# Python code to convert list of tuple into list
 
 
# List of tuple initialization
tup = [(1, 2), (3, 4), (5, 6)]
 
# Using map for 0 index
b = map(lambda x: x[0], tup)
 
# Using map for 1 index
c = map(lambda x: x[1], tup)
 
# converting to list
b = list(b)
c = list(c)
 
# Combining output
out = b + c
 
# printing output
print(out)

Output:

[1, 3, 5, 2, 4, 6]

Method #6: Using enumerate function

Python3




tup = [('1', '2'), ('3', '4'), ('5', '6')]
x=[int(j) for a,i in enumerate(tup) for j in i  ]
print(x)

Output

[1, 2, 3, 4, 5, 6]

Method: Using zip 

Python3




print(list(*zip(*[(1,), (2,), (3,)])))

Output

[1, 2, 3]

Method: Using eval 

Python3




tup = [('1', '2'), ('3', '4'), ('5', '6')]
x=[eval(j) for i in tup for j in i  ]
print(x)

Output

[1, 2, 3, 4, 5, 6]

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!