Basic split
Input
chunk_list([1, 2, 3, 4, 5, 6], 3)
Output
[[1, 2, 3], [4, 5, 6]]
The list divides exactly into two chunks of size 3.
Full lesson preview
Break a list into consecutive sublists of a given size. The last chunk may be smaller if elements don't divide evenly.
Problem statement
Task
Examples
Input
chunk_list([1, 2, 3, 4, 5, 6], 3)
Output
[[1, 2, 3], [4, 5, 6]]
The list divides exactly into two chunks of size 3.
Input format
Output format
Constraints
Samples
Input
chunk_list([1,2,3,4,5], 2)
Output
[[1, 2], [3, 4], [5]]
Creates pairs; the final chunk has the remaining element.