k3dict
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.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| k3dict-0.1.15.tar.gz | 17.1 kB | Without provenance | Details for k3dict-0.1.15.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| k3dict-0.1.15-py3-none-any.whl | Python 3 | none | any | Details for k3dict-0.1.15-py3-none-any.whl |
Total release size: 27.2 kB
Release files / k3dict-0.1.15.tar.gz
| Download URL | k3dict-0.1.15.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c29041bbaff6ed2a43d3284ac8824fa7809ff957b354faf8f87fd141c1d5264
|
|
BLAKE2b-256 checksum How to use checksums |
0911a8d3e9ed1ae67f6c21ed67485d2fc71c8269d434806cdc6108994f33de37
|
| 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.15-py3-none-any.whl
| Download URL | k3dict-0.1.15-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93f3258a87a9b14adc0946eed69da1c538d8ff062696da30b00ae652b74651ce
|
|
BLAKE2b-256 checksum How to use checksums |
2d08f65e67920507f8bf0f995b07ef537e0cd00fd2225cf6f618433b0bfc9a40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for k3dict 0.1.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.