Python | Convert list of tuples into list
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
# Python code to convert list of tuples into list # List of tuple initializationlt = [('Geeks', 2), ('For', 4), ('geek', '6')] # using list comprehensionout = [item for t in lt for item in t] # printing outputprint(out) |
Output:
['Geeks', 2, 'For', 4, 'geek', '6']
Method #2 : Using itertools
# Python code to convert list of tuple into list # Importingimport itertools # List of tuple initializationtuple = [(1, 2), (3, 4), (5, 6)] # Using itertoolsout = list(itertools.chain(*tuple)) # printing outputprint(out) |
Output:
[1, 2, 3, 4, 5, 6]
Method #3 : Using iteration
# Python code to convert list of tuple into list # List of tuple initializationtup = [(1, 2), (3, 4), (5, 6)] # result list initializationresult = [] for t in tup: for x in t: result.append(x) # printing outputprint(result) |
Output:
[1, 2, 3, 4, 5, 6]
Method #4 : Using sum
# Python code to convert list of tuple into list # List of tuple initializationtup = [(1, 2), (3, 4), (5, 6)] # using sum function()out = list(sum(tup, ())) # printing outputprint(out) |
Output:
[1, 2, 3, 4, 5, 6]
Method #5 : Using operator and reduce
# Python code to convert list of tuple into list import operatorfrom functools import reduce # List of tuple initializationtup = [(1, 2), (3, 4), (5, 6)] # printing outputprint(list(reduce(operator.concat, tup))) |
Output:
[1, 2, 3, 4, 5, 6]
Method #6 : Using lambda
# Python code to convert list of tuple into list # List of tuple initializationtup = [(1, 2), (3, 4), (5, 6)] # Using map for 0 indexb = map(lambda x: x[0], tup) # Using map for 1 indexc = map(lambda x: x[1], tup) # converting to listb = list(b)c = list(c) # Combining outputout = b + c # printing outputprint(out) |
Output:
[1, 3, 5, 2, 4, 6]
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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


