Skip to main content

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyaccessors-0.0.5-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

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

Hashes for pyaccessors-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f120c30669308be48d2102c982a07f0872ec96a39d55d217df9730448c0a8d16
MD5 2ce829f6563ed1815ca0fb88e97db90d
BLAKE2b-256 184f7b88534f744cc1d132a0e1fbf6a18fdfb06a8e01883b45921bed1b67b941

See more details on using hashes here.

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

Hashes for pyaccessors-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8b5ab306b8a14eb4672489cb7001df5ee510a67488a8a26d9e6d55097556fce3
MD5 8e6e9441c962d30eb3246854ef17d98d
BLAKE2b-256 0f78c94125cf65041e7f2936b7cd48e9211070528eb811d0d30e9ea6cbc0a9bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page