Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:43:50 +03:00
parent ab1ea476c5
commit a5ca5190e5
169 changed files with 0 additions and 626 deletions

26
python/snippets/chunk.md Normal file
View File

@ -0,0 +1,26 @@
---
title: Split list into chunks
type: snippet
tags: [list]
cover: red-berries
dateModified: 2020-11-02T19:27:07+02:00
---
Chunks a list into smaller lists of a specified size.
- Use `list()` and `range()` to create a list of the desired `size`.
- Use `map()` on the list and fill it with splices of the given list.
- Finally, return the created list.
```py
from math import ceil
def chunk(lst, size):
return list(
map(lambda x: lst[x * size:x * size + size],
list(range(ceil(len(lst) / size)))))
```
```py
chunk([1, 2, 3, 4, 5], 2) # [[1, 2], [3, 4], [5]]
```