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.3.1.tar.gz (3.8 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.3.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PySatchel-0.3.1.tar.gz
  • Upload date:
  • Size: 3.8 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.3.1.tar.gz
Algorithm Hash digest
SHA256 312200f1a8637a0edb68fe6e5ebb98a7d51d72157196064cb48cc8ee59ffd9c9
MD5 5986dbc195fa464adac2ab25690bfd6e
BLAKE2b-256 4ff255dd42d7f00d72ea69e34ebd2b47857499edb1059fa9357fce0c52113857

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySatchel-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de45d553709c53ffdb6af629d6808bb71a2e7a5937b6814a4e7f140302fe833b
MD5 392460c6b34c263768641556f0df46e4
BLAKE2b-256 74d8c345338024d1f76a554875421daa54357e454f6c70b50079d3c2ecc7d75b

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