Python: Chunk a given list into n smaller lists
Chunk List into N Parts
Write a Python program to chunk a given list into n smaller lists.
- Use math.ceil() and len() to get the size of each chunk.
- Use list() and range() to create a new list of size n.
- Use map() to map each element of the new list to a chunk the length of size.
- If the original list can't be split evenly, the final chunk will contain the remaining elements.
Sample Solution:
Python Code:
Sample Output:
[[1, 2], [3, 4], [5, 6], [7]]
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to split a list into n nearly equal parts, distributing extra elements evenly among the parts.
- Write a Python program to partition a list into n parts and then reverse the order of the parts.
- Write a Python program to split a list into n parts and pad the shorter parts with None to equalize their lengths.
- Write a Python program to divide a list into n parts and calculate the sum of the elements in each part.
Python Code Editor:
Previous: Write a Python program to chunk a given list into smaller lists of a specified size.
Next: Write a Python program to convert a given number (integer) to a list of digits.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics