Skip to main content

No project description provided

Project description

Dollop

A python package for splitting up iterables into smaller portions 🥣.

Installation

pip install dollop

Usage

Supports:

  • Sequences: list, tuple, str, range, bytes, bytearray or any other sequence-like object.
  • Pandas objects: pd.DataFrame, pd.Series.
  • Array-like objects: np.ndarray, torch.Tensor.
  • Files: either as a file path or handle.

Example usage (automatically checks object type):

from dollop import serve

for serving in serve('Dolloping all day long', serving_size=6):
    print(serving)

for serving in serve((1, 1, 2, 3, 5, 8, 13, 21, 34, 55), serving_size=4):
    print(serving)

Output:

Dollop
ing al
l day 
long
(1, 1, 2, 3)
(5, 8, 13, 21)
(34, 55)

The serving_size parameter defines how many items/lines/characters/etc. you want in each dollop!

To use type-specific dollop:

  • Sequences: from dollop.sequence import serve.
  • Pandas: from dollop.pandas import serve
  • Files: from dollop.file import serve.

For dollop.file you can specify mode=lines or mode=chars to read the file line-by-line or character-by-character.

See also

The more_itertools and later (Python 3.12+) itertools packages have something similar:

from more_itertools import chunked

chunks = chunked(iterable, n))

and

from itertools import batched

batches = batched(iterable, n))

However these both have the major disadvantage that typing is not preserved, for example chunking/batching a string does not return an iterable of strings, but an iterable of tuples.

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

dollop-1.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

dollop-1.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file dollop-1.1.0.tar.gz.

File metadata

  • Download URL: dollop-1.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dollop-1.1.0.tar.gz
Algorithm Hash digest
SHA256 8d2e4e3e4152642eef8377487a03473d0b919991416c5b8c1ada5f217ddb1774
MD5 1ae4bcef306867acdfa6179aa285e084
BLAKE2b-256 28f064fad137c44ea4c1269cbd9c74f58a831fd125a254b9d9516f892e8360c6

See more details on using hashes here.

File details

Details for the file dollop-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: dollop-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dollop-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 245a3056d4e972bb2b76524527b867a7396c2b2f920baf52c5e07f6a4343dd37
MD5 2234ebdf5823bf513895cde23e3b9443
BLAKE2b-256 94bb6767d58cdfd9d8a9f4e32138705c851ebac745b205cbbce69b2ad17f8ae5

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