Split a list into batches

Mediumrange with a stepslicing· 20 XP

An API accepts at most size user ids per request, so a long list of ids has to be sent in batches.

Write a function batches(items, size) that returns a list of lists, each holding at most size items, in the original order. The last batch can be shorter.

How it's checked

Your code runs, then the check below runs and its printed output is compared with ours.

  • batches([1, 2, 3, 4, 5], 2) returns [[1, 2], [3, 4], [5]]

Hints, the later steps and the answer come with Pro.

def batches(items, size):
    ...