Skip to main content

Split iterables into evenly sized chunks

Project description

philiprehberger-list-chunk

Tests PyPI version License

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

  • 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

philiprehberger_list_chunk-0.1.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_list_chunk-0.1.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_list_chunk-0.1.4.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_list_chunk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6d4dad57c37f6214aa1f269c3fffc3271e7d39f0ad8b902d51da61914d02c8db
MD5 1f791cf04a88316468a48a6824570296
BLAKE2b-256 2e77b9c841cc71e09ac8ada13d78ccc5eaf8c4afa9768f862c4433e11f8f13a0

See more details on using hashes here.

File details

Details for the file philiprehberger_list_chunk-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_list_chunk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c1329a4978cc81f8196d01088ccd9bd3f255c58fcfe8e651fae1075438bf1164
MD5 d99748847f80c07c894b56db69136579
BLAKE2b-256 9d1817300b14f027819c23127c487c7bfcba125a2f4c5fa342eba88a8c92eb2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page