Skip to main content

Satchel is a compendium of pure python functions to carry with you and get things done.

Project description

Satchel

Satchel is a compendium of pure python functions to carry with you and get things done.

Installation

pip install PySatchel

Usage

Sometimes it is useful to split a list into smaller lists to work with.

>>> import satchel import chunk

>>> some_list = [1, 2, 3, 4, 5]
>>> chunk(some_list, 2, "length", True)
# [[1, 2], [3, 4], [5]]

>>> chunk(some_list, 2, "count", True)
# [[1, 2, 3], [3, 5]]

You can also group values and apply a function to the groups.

>>> import satchel import groupapply

>>> string = "AAABBAAAACCB"
>>> groupapply(string, apply="count")
# {'A': 7, 'B': 3, 'C': 2}

>>> data = [1, 1, 2, 2, 2, 1, 4]
>>> groupapply(data, key=lambda x: "lower" if x < 3 else "higher", apply="count")
# {'lower': 6, 'higher': 1}

>>> data = [
    {"label": "a", "val": 1},
    {"label": "a", "val": 10},
    {"label": "a", "val": 4},
    {"label": "b", "val": 6},
    {"label": "b", "val": 3},
]
>>> groupapply(data, lambda d: d["label"], lambda l: sum([d["val"] for d in l]))
# {'a': 15, 'b': 9}

>>> data = [
    {"label": "a", "val": 1},
    {"label": "a", "val": 1},
    {"label": "a", "val": 1},
    {"label": "b", "val": 2},
    {"label": "b", "val": 2},
]
>>> groupapply(data, "label", "count")
# {'a': 3, 'b': 2}

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

PySatchel-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

PySatchel-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file PySatchel-0.1.0.tar.gz.

File metadata

  • Download URL: PySatchel-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Darwin/21.6.0

File hashes

Hashes for PySatchel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0244be205ff2c309a08a2e42188ad5654f716532acd462f62d67a9ca9088211d
MD5 7486fe8b60cfe2ed239c3324ececc6f0
BLAKE2b-256 8dcb119240887165d85f1577bddc2964541b9b24e95a228c92b7f02e1e1ddccb

See more details on using hashes here.

File details

Details for the file PySatchel-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: PySatchel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Darwin/21.6.0

File hashes

Hashes for PySatchel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0dbdefbf5dae78aa8157267d324261e7b69a17b7f9631282673b7b4e7b59b3d5
MD5 507b59e1da2d0ba69963e1bd354721f9
BLAKE2b-256 d7a6c6e287edca2a927ada611d3e5567e01817d11d0af06ae9a001eb58ce0c7b

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