On this page
article
Chunk a List
Split a list into fixed-size batches.
Category: basics
Problem
Split a list into fixed-size batches.
Solution
chunks = [lst[i:i+n] for i in range(0, len(lst), n)]
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path