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},
#     "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


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)

Uploaded Source

Built Distribution

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

pyaccessors-0.0.4-py3-none-any.whl (2.3 kB view details)

Uploaded Python 3

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

Hashes for pyaccessors-0.0.4.tar.gz
Algorithm Hash digest
SHA256 79d1fd842237cce5ae0f1cc32e73048cec8952cde4d0eeecf19e59f726a7c9bd
MD5 3b83041ca288a69b3424e99d17d4c3ac
BLAKE2b-256 ed516e50106789b25f4c8fb047f3382861c21634502ece4f49198c7ffb65b5af

See more details on using hashes here.

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

Hashes for pyaccessors-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8bf70173e1377b28cf01c51b268d6a455460f9b9950f03b4a5850fabc99c1d86
MD5 8b17dc3af5f578f9b5ea0a10f8c48bc4
BLAKE2b-256 1802513f1bc44e8633f9b4716e9db0c29f4bcaa9ef79b0d0487041e280b50dc6

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