How do I make a flat list out of a list of lists?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
In Python, you can flatten a list of lists into a single flat list using various methods. Here are some of the most common approaches:
1. Using a List Comprehension
List comprehensions provide a concise way to flatten a list of lists:
Output:
2. Using itertools.chain
The itertools.chain function is another efficient way to flatten a list of lists:
Output:
Alternatively, you can also use itertools.chain.from_iterable which avoids the unpacking of the list:
3. Using sum()
Although less common, you can use sum() with an empty list as the start value:
Output:
4. Using functools.reduce
You can also use functools.reduce to flatten a list of lists:
Output:
5. Using numpy (if your lists are numerical and you have NumPy installed)
If you're dealing with numerical data, you can use numpy's flatten method:
Output:
Summary
- List Comprehension: Simple and Pythonic.
itertools.chain: Efficient for large lists.sum(): Simple but less efficient for large lists.functools.reduce: Less common, but a functional approach.numpy.flatten: Great for numerical data, but requires NumPy.
The best method depends on your specific use case, but list comprehension and itertools.chain are generally the most common and efficient ways to flatten a list of lists in Python.
Related reading
- How do I sort a dictionary by value?
- How do I split a list into equally-sized chunks?
- How to iterate over a dictionary?
- Loop (for each) over an array in JavaScript
- How do I put a time delay in a Python script?
- How slicing in Python works
- Sort array of objects by string property value
- What and where are the stack and heap?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.