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)
| File | Size | Uploaded | |
|---|---|---|---|
| pyaccessors-0.0.5.tar.gz | 3.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|