List Batches

Large lists are often easier to process in smaller batches, such as sending data in groups or showing items page by page. Write a function chunk that splits the list arr into sublists with at most size elements each. Keep the original element order. If there are not enough elements to fill the last chunk, it should simply be shorter.

Примеры

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

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

def chunk(arr: list, size: int) -> list:

Теги

listsarray
PostgreSQLv16

Ovdje će se prikazati rezultat izvršavanja koda

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