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
Connectez-vous pour voir l'historique des soumissions
Se connecterConnectez-vous pour utiliser le Mentor IA
Se connecterVisible tests
1
Input
[1,2,3,4,5], 2Expected
[[1,2],[3,4],[5]]2
Input
[1,2,3], 3Expected
[[1,2,3]]3
Input
[], 4Expected
[]4
Input
[1,2,3,4], 1Expected
[[1],[2],[3],[4]]5
Input
[1,2], 10Expected
[[1,2]]6
Input
[7,7,7,7,7], 2Expected
[[7,7],[7,7],[7]]Focus radio
Paused · SomaFM · Fluid