In this tutorial, we’ll look at how to flatten a list of tuples in Python to a single list through some examples.
How to flatten a list of tuples?

There are a number of ways to flatten a list of tuples in python. You can use a list comprehension, the itertools
library, or simply loop through the list of tuples adding each item to a separate list, etc. Let’s see them in action through examples followed by a runtime assessment of each.
1. Naive method – Iterate over the list of tuples
Here, we iterate through each item of all the tuples in a nested loop and append them to a separate list.
# list of tuples ls = [('a','b','c'),('d','e','f'),('g','h','i')] # iterate through list of tuples in a nested loop flat_ls = [] for tup in ls: for item in tup: flat_ls.append(item) # display the lists print("Original list:", ls) print("Flattened list:", flat_ls)
Output:
Original list: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] Flattened list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
In the above example, the outer loop iterates over all the tuples while the inner loop iterates over each item of a tuple appending it to the list flat_ls
.
Highlighted programs for you
Flatiron School
Flatiron School
University of Maryland Global Campus
University of Maryland Global Campus
Creighton University
Creighton University
2. Using list comprehension
You can also use a list comprehension to basically do the same thing as in the previous step but with better readability and faster execution.
# list of tuples ls = [('a','b','c'),('d','e','f'),('g','h','i')] # flatten using list comprehension flat_ls = [item for tup in ls for item in tup] # print print("Original list:", ls) print("Flattened list:", flat_ls)
Output:
Original list: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] Flattened list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
Here, we use list comprehension to create a flattened list by keeping each item of each of the tuples in the original list. Using list comprehension is similar to nested looping but has better readability (in this use case).
3. Using the itertools
library to flatten list of tuples
The python itertools
standard library offers handy functionalities for working with iterables. Here, we break the list of tuples into individual parts and then chain them together into a single iterable.
import itertools # list of tuples ls = [('a','b','c'),('d','e','f'),('g','h','i')] # using itertools flat_ls = list(itertools.chain(*ls)) # print print("Original list:", ls) print("Flattened list:", flat_ls)
Output:
Original list: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] Flattened list: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
We get the resulting flattened list with all the elements from each tuple.
You might also be interested in –
- Python – Flatten a list of lists to a single list
- Convert Tuple to a Set in Python – With Examples
- Convert Tuple to a List in Python – With Examples
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.
Christian
Thursday 10th of February 2022
Nice and simple, thanks! I think it would be better if both example 1 and example 2 kept the same names for variables so one could have a better understanding of list comprehensions -- like flat_ls = [] for tup in ls: for item in tup: flat_ls.append(item) Thank you.
Piyush
Thursday 10th of February 2022
Thank you for pointing it out. It definitely makes more sense to use the same variable names across the two examples as you suggest. We have updated the tutorial accordingly.