Skip to main content

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

  • 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

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.1.tar.gz (3.9 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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_list_chunk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6e711cf0881b0e2e3467ec83f7d3b4be027fb44ea39e0ae15a12e131f1c6186f
MD5 170784d4aeec1c234a982bea045be943
BLAKE2b-256 bd38d231af0795811283acb1d7f04df7143a0fbb1da601d2d90af87af735c21a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_list_chunk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 564f07986dca26ab4942048cac32794ec76afd224410d081023a5fe40f755640
MD5 02db31efd9c0f4451de48b200cd6f501
BLAKE2b-256 dc53f5602e04495755a6fca8f7d96245467d2a8f96a83b17a772d076afa04a69

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