On this page
article
Flatten Nested List
Flatten one level of nesting.
Category: basics
Problem
Flatten one level of nesting.
Solution
flat = [x for sub in nested for x in sub]
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path