Split iterables into evenly sized chunks
Project description
philiprehberger-list-chunk
Split iterables into evenly sized chunks.
Installation
pip install philiprehberger-list-chunk
Usage
from philiprehberger_list_chunk import chunk, chunk_by, sliding_window, interleave, flatten
chunk([1, 2, 3, 4, 5], size=2)
# [[1, 2], [3, 4], [5]]
chunk([1, 2, 3], size=2, pad=0)
# [[1, 2], [3, 0]]
chunk_by([1, 1, 2, 2, 3], key=lambda x: x)
# [[1, 1], [2, 2], [3]]
sliding_window([1, 2, 3, 4, 5], size=3)
# [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
interleave([1, 2, 3], ["a", "b", "c"])
# [1, "a", 2, "b", 3, "c"]
flatten([[1, 2], [3, 4]])
# [1, 2, 3, 4]
API
| Function / Class | Description |
|---|---|
chunk(items, size, pad=None) |
Fixed-size chunks |
chunk_by(items, key) |
Group consecutive elements by key |
sliding_window(items, size, step=1) |
Sliding window views |
interleave(*iterables) |
Round-robin interleave |
flatten(nested) |
Flatten one level of nesting |
Development
pip install -e .
python -m pytest tests/ -v
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_list_chunk-0.1.6.tar.gz.
File metadata
- Download URL: philiprehberger_list_chunk-0.1.6.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e20ee80b0354e7dad444f21706e7e80fb55546af4704fedeee4845fc7045076
|
|
| MD5 |
384f64b8b5c196f3e50c4ed2629bf714
|
|
| BLAKE2b-256 |
30a2eb69830369fc94777f51e198e77bd1dc797a30d544d5c940551f3537bf54
|
File details
Details for the file philiprehberger_list_chunk-0.1.6-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_list_chunk-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2408fe9eeab498286611d5d0e229bfd7a0cc94413f9856c12710c4495c6c9bb7
|
|
| MD5 |
35accdf1de5794ca982942b28317dfd5
|
|
| BLAKE2b-256 |
a1bfc49dfe32bdb976d46cfde82981fa33edf1e56d0b35eb3f4e48d5d62f1526
|