Access lists of dictionaries with their keys' values
Project description
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}},
# }
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
pyaccessors-0.0.5.tar.gz
(3.0 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 pyaccessors-0.0.5.tar.gz.
File metadata
- Download URL: pyaccessors-0.0.5.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f120c30669308be48d2102c982a07f0872ec96a39d55d217df9730448c0a8d16
|
|
| MD5 |
2ce829f6563ed1815ca0fb88e97db90d
|
|
| BLAKE2b-256 |
184f7b88534f744cc1d132a0e1fbf6a18fdfb06a8e01883b45921bed1b67b941
|
File details
Details for the file pyaccessors-0.0.5-py3-none-any.whl.
File metadata
- Download URL: pyaccessors-0.0.5-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b5ab306b8a14eb4672489cb7001df5ee510a67488a8a26d9e6d55097556fce3
|
|
| MD5 |
8e6e9441c962d30eb3246854ef17d98d
|
|
| BLAKE2b-256 |
0f78c94125cf65041e7f2936b7cd48e9211070528eb811d0d30e9ea6cbc0a9bb
|