Skip to main content

Pyaccessors: The key to lists

Install

pip install pyaccessors

Usage

Unique Access

from pyaccessors import access

list_of_dicts = [
    {"a": "A1", "b": 1},
    {"a": "A2", "b": 2},
    {"a": "A3", "b": 3},
]

accessor = access(list_of_dict, by="a")

# if you want to fail when the key does not exist
# accessor = access(list_of_dict, by="a", strict=True)

print(accessor)
# {
#     "A1": {"a": "A1", "b": 1}, 
#     "A2": {"a": "A2", "b": 2},
#     "A3": {"a": "A3", "b": 3},
# }

Grouped Access

from pyaccessors import access

list_of_dicts = [
    {"a": "A1", "b": 1},
    {"a": "A1", "b": 2},
    {"a": "A2", "b": 3},
]

accessor = access(list_of_dict, by="a", group=True)
print(accessor)
# {
#     "A1": [{"a": "A1", "b": 1}, {"a": "A1", "b": 2}],
#     "A2": [{"a": "A2", "b": 3}],
# }

Deep Access

from pyaccessors import access

list_of_dicts = [
    {"a": "A1", "b": {"c": 1}},
    {"a": "A1", "b": {"c": 2}},
    {"a": "A2", "b": {"c": 3}},
]

accessor = access(list_of_dict, by=["b", "c"])
print(accessor)
# {
#     1: {"a": "A1", "b": {"c": 1}},
#     2: {"a": "A1", "b": {"c": 2}},
#     3: {"a": "A2", "b": {"c": 3}},
# }

Metadata

Release files for pyaccessors 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyaccessors 0.0.5
File Size Uploaded
pyaccessors-0.0.5.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyaccessors 0.0.5
File Interpreter ABI Platform
pyaccessors-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 6.8 kB

Release files / pyaccessors-0.0.5.tar.gz

Download URL pyaccessors-0.0.5.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f120c30669308be48d2102c982a07f0872ec96a39d55d217df9730448c0a8d16
BLAKE2b-256 checksum
How to use checksums
184f7b88534f744cc1d132a0e1fbf6a18fdfb06a8e01883b45921bed1b67b941
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / pyaccessors-0.0.5-py3-none-any.whl

Download URL pyaccessors-0.0.5-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b5ab306b8a14eb4672489cb7001df5ee510a67488a8a26d9e6d55097556fce3
BLAKE2b-256 checksum
How to use checksums
0f78c94125cf65041e7f2936b7cd48e9211070528eb811d0d30e9ea6cbc0a9bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page