Split a list into chunks
Return consecutive list chunks of at most size elements, preserving order. size is positive. The final chunk may be shorter.
items = [1, 2, 3, 4, 5]
print(list(range(0, len(items), 2)))
print(items[4:6])Reason about the state
Advance the start index by size and slice at each boundary. Slices produce independent output lists. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return consecutive list chunks of at most size elements, preserving order. size is positive. The final chunk may be shorter.
The explanation opens here once every check passes.