Python: Chunk a given list into smaller lists of a specified size
Chunk List by Size
Write a Python program to chunk a given list into smaller lists of a specified size.
- Use list() and range() to create a list of the desired size.
- Use map() on the list and fill it with splices of the given list.
- Finally, return the created list.
Sample Solution:
Python Code:
Sample Output:
[[1, 2, 3], [4, 5, 6], [7, 8]]
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to divide a list into chunks of a specified size and then reverse every other chunk.
- Write a Python program to split a list into chunks of a given size and compute the sum of elements in each chunk.
- Write a Python program to chunk a list into segments of a specified size and output a list of the chunk lengths.
- Write a Python program to divide a list into fixed-size chunks and then flatten the resulting list of lists.
Go to:
Previous: Write a Python program to split values into two groups, based on the result of the given filter list.
Next: Write a Python program to chunk a given list into n smaller lists.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.