Batch the List

Large lists are often processed in batches so a program does not send or calculate everything at once. Given a list items and a batch size size, split the items into consecutive batches. Each batch should contain at most size elements, and the last batch may be shorter.

Примеры

Ввод
[1, 2, 3, 4, 5], 2
Вывод
[[1, 2], [3, 4], [5]]
Ввод
[1, 2, 3], 3
Вывод
[[1, 2, 3]]
Ввод
[], 4
Вывод
[]

Нужно реализовать

def batch_chunks(items: list, size: int) -> list:

Теги

listsarray
PostgreSQLv16

Тук ще се появи резултатът от изпълнението на кода

Visible tests
1
Input
[1,2,3,4,5], 2
Expected[[1,2],[3,4],[5]]
2
Input
[1,2,3], 3
Expected[[1,2,3]]
3
Input
[], 4
Expected[]
4
Input
[1,2,3,4], 1
Expected[[1],[2],[3],[4]]
5
Input
[1,2], 10
Expected[[1,2]]
6
Input
[7,7,7,7,7], 2
Expected[[7,7],[7,7],[7]]
Focus radio
Paused · SomaFM · Fluid