changing-array-to-list

This commit is contained in:
vignesh
2018-04-14 08:35:58 +05:30
parent d3c9524379
commit 841385b5ed
9 changed files with 45 additions and 45 deletions

View File

@ -1,17 +1,17 @@
### chunk
### chunk
Chunks an array into smaller lists of a specified size.
Chunks an list into smaller lists of a specified size.
Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `arr`.
Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `lst`.
```python
from math import ceil
def chunk(arr, size):
def chunk(lst, size):
return list(
map(lambda x: arr[x * size:x * size + size],
list(range(0, ceil(len(arr) / size)))))
map(lambda x: lst[x * size:x * size + size],
list(range(0, ceil(len(lst) / size)))))
```
``` python