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},
# "A2": {"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.4.tar.gz
(1.6 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.4.tar.gz.
File metadata
- Download URL: pyaccessors-0.0.4.tar.gz
- Upload date:
- Size: 1.6 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.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79d1fd842237cce5ae0f1cc32e73048cec8952cde4d0eeecf19e59f726a7c9bd
|
|
| MD5 |
3b83041ca288a69b3424e99d17d4c3ac
|
|
| BLAKE2b-256 |
ed516e50106789b25f4c8fb047f3382861c21634502ece4f49198c7ffb65b5af
|
File details
Details for the file pyaccessors-0.0.4-py3-none-any.whl.
File metadata
- Download URL: pyaccessors-0.0.4-py3-none-any.whl
- Upload date:
- Size: 2.3 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.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bf70173e1377b28cf01c51b268d6a455460f9b9950f03b4a5850fabc99c1d86
|
|
| MD5 |
8b17dc3af5f578f9b5ea0a10f8c48bc4
|
|
| BLAKE2b-256 |
1802513f1bc44e8633f9b4716e9db0c29f4bcaa9ef79b0d0487041e280b50dc6
|