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

Uploaded Python 3

File details

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

File metadata

  • Download URL: PySatchel-0.2.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.2.1.tar.gz
Algorithm Hash digest
SHA256 00614e65017ae7165c11aaf0679512ef1b78165eeaa7258b45b1ae31f75eae95
MD5 467a95fd2fd46140442efc61a0da88b5
BLAKE2b-256 16791baabd0758ec6277164ddbe5216540bb23356dd938acfebf15f788d906eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySatchel-0.2.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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 51734dec842ba9b3fce66ec6a4e8d99e81b2cf49c377bd697ebcaa4b2c306368
MD5 26be57d305e49d292d76ce531bc2c090
BLAKE2b-256 cc8543c610d4bf6b38079eaa161323a442db22493041e196cb0ce355447269a8

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