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.2.0.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.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PySatchel-0.2.0.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.2.0.tar.gz
Algorithm Hash digest
SHA256 28426048fc7685b53cc94f6f668e66408b4a4e8b3c70d7267b0001f9885a36d6
MD5 2bdb6ddad83b345bd9168d9f82ffdf53
BLAKE2b-256 175866aea7628b79ea59bf758279788f7340106943db22c50c75e93d90ba5a56

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySatchel-0.2.0-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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa8dd2355ffdeed80982547b832ff84557122656377b8d54c30b71dedca25d0d
MD5 4b82cb49e15d13d2f4d74a4292273f10
BLAKE2b-256 1784e49fe7c0ce230f541094f8b2bc7206c71a6ea071584ca60e893121a7896a

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