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
Release history Release notifications | RSS feed
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.0.tar.gz
(3.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PySatchel-0.3.0.tar.gz.
File metadata
- Download URL: PySatchel-0.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a171755d824d93ba02e91a6644a04cfc4a0d6285f9519bec608755092c9fba69
|
|
| MD5 |
9852cd67761172b4923b2b112d12e286
|
|
| BLAKE2b-256 |
1bda57336f97a5c9b2d99acd6d1f4da0c398dbcd2303f6befaf55328fac2ee86
|
File details
Details for the file PySatchel-0.3.0-py3-none-any.whl.
File metadata
- Download URL: PySatchel-0.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
938aaa2391082c13394631307d018caaeb7bebd29cea547a4b1165eabb2c1f48
|
|
| MD5 |
448607cc093354cbf6610b55fe967bc0
|
|
| BLAKE2b-256 |
cba7a6a93f71c01db54caf85fe90bf26a5c9c6067dea31e8ab7d86f4ab2f1254
|