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 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) |
chevron_right
filter_none
Output:
['Geeks', 2, 'For', 4, 'geek', '6']
Method #2 : Using itertools
# 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) |
chevron_right
filter_none
Output:
[1, 2, 3, 4, 5, 6]
Method #3 : Using iteration
# 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) |
chevron_right
filter_none
Output:
[1, 2, 3, 4, 5, 6]
Method #4 : Using sum
# 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) |
chevron_right
filter_none
Output:
[1, 2, 3, 4, 5, 6]
Method #5 : Using operator and reduce
# 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))) |
chevron_right
filter_none
Output:
[1, 2, 3, 4, 5, 6]
Method #6 : Using lambda
# 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) |
chevron_right
filter_none
Output:
[1, 3, 5, 2, 4, 6]
Recommended Posts:
- Python | Convert list of tuples to list of list
- Python | Convert list of strings to list of tuples
- Python | Convert list of tuples to list of strings
- Python | Convert a list of Tuples into Dictionary
- Python | Convert list of tuples into digits
- Python | Convert dictionary to list of tuples
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Remove tuples from list of tuples if greater than n
- Python | Count tuples occurrence in list of tuples
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Remove duplicate tuples from list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Update a list of tuples using another list
- Python | Combining tuples in list of tuples
- Python | Convert list of string to list of list
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.



