Skip to main content

k3dict

Action-CI Documentation Status Package

It provides with several dict operation functions.

k3dict is a component of pykit3 project: a python3 toolkit set.

k3dict

It provides with several dict operation functions.

Status

This library is considered production ready.

Install

pip install k3dict

Synopsis

import k3dict

mydict = {"a": {"a.a": "v-a.a", "a.b": {"a.b.a": "v-a.b.a"}, "a.c": {"a.c.a": {"a.c.a.a": "v-a.c.a.a"}}}}

# depth-first iterative the dict
for rst in k3dict.depth_iter(mydict):
    print(rst)

# output:
#     (['a', 'a.c', 'a.c.a', 'a.c.a.a'], 'v-a.c.a.a')
#     (['a', 'a.b', 'a.b.a'], 'v-a.b.a')
#     (['a', 'a.a'], 'v-a.a')

for rst in k3dict.breadth_iter(mydict):
    print(rst)

# output:
#     (['a'],                            {'a.c': {'a.c.a': {'a.c.a.a': 'v-a.c.a.a'}}, 'a.b': {'a.b.a': 'v-a.b.a'}
#                                           , 'a.a': 'v-a.a'})
#     (['a', 'a.a'],                     'v-a.a')
#     (['a', 'a.b'],                     {'a.b.a': 'v-a.b.a'})
#     (['a', 'a.b', 'a.b.a'],            'v-a.b.a')
#     (['a', 'a.c'],                     {'a.c.a': {'a.c.a.a': 'v-a.c.a.a'}})
#     (['a', 'a.c', 'a.c.a'],            {'a.c.a.a': 'v-a.c.a.a'})
#     (['a', 'a.c', 'a.c.a', 'a.c.a.a'], 'v-a.c.a.a')
#

records = [
    {
        "event": "log in",
        "time": {
            "hour": 10,
            "minute": 30,
        },
    },
    {
        "event": "post a blog",
        "time": {
            "hour": 10,
            "minute": 40,
        },
    },
    {
        "time": {
            "hour": 11,
            "minute": 20,
        },
    },
    {
        "event": "log out",
        "time": {
            "hour": 11,
            "minute": 20,
        },
    },
]

get_event = k3dict.make_getter("event", default="NOTHING DONE")
get_time = k3dict.make_getter("time.$field")

for record in records:
    ev = get_event(record)

    hour = get_time(record, {"field": "hour"})
    minute = get_time(record, {"field": "minute"})
    tm = f"{hour:d}:{minute:d}"

    print(f"{ev:<12}   at {tm}")

# output:
# log in         at 10:30
# post a blog    at 10:40
# NOTHING DONE   at 11:20
# log out        at 11:20

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3dict 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3dict 0.1.12
File Size Uploaded
k3dict-0.1.12.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3dict 0.1.12
File Interpreter ABI Platform
k3dict-0.1.12-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / k3dict-0.1.12.tar.gz

Download URL k3dict-0.1.12.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a055036ba63486ee89aed0d9072302a2008058d4b01fcbd7613caaf1cc67b36b
BLAKE2b-256 checksum
How to use checksums
85e2c280774932c66d74df00f6522c104ac2bd5eff5e4e82a3d996fa67a23f2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3dict-0.1.12-py3-none-any.whl

Download URL k3dict-0.1.12-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd63fda0d4c82c2f276dded9a8b44fc765c81a0231e3774027fbb6b6c0c1434e
BLAKE2b-256 checksum
How to use checksums
1bc79ec71b6ad261b72fae00baf9796a200efd4fc9a97d35586ebeb9884fb738
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.1.15

2 release files

This release

0.1.12 This release

2 release files

0.1.9

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page